mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
move the OOP-setup bits down into that section for clarity. JavaScript allows this it's pre-declaration pass.
This commit is contained in:
@@ -45,20 +45,6 @@
|
|||||||
nativeIsArray = Array.isArray,
|
nativeIsArray = Array.isArray,
|
||||||
nativeKeys = Object.keys;
|
nativeKeys = Object.keys;
|
||||||
|
|
||||||
// If Underscore is called as a function, it returns a wrapped object that
|
|
||||||
// can be used OO-style. This wrapper holds altered versions of all the
|
|
||||||
// underscore functions. Wrapped objects may be chained.
|
|
||||||
var wrapper = function(obj) { this._wrapped = obj; };
|
|
||||||
|
|
||||||
// A method to easily add functions to the OOP wrapper.
|
|
||||||
var addToWrapper = function(name, func) {
|
|
||||||
wrapper.prototype[name] = function() {
|
|
||||||
var args = _.toArray(arguments);
|
|
||||||
unshift.call(args, this._wrapped);
|
|
||||||
return result(func.apply(_, args), this._chain);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create a safe reference to the Underscore object for reference below.
|
// Create a safe reference to the Underscore object for reference below.
|
||||||
var _ = function(obj) { return new wrapper(obj); };
|
var _ = function(obj) { return new wrapper(obj); };
|
||||||
|
|
||||||
@@ -645,11 +631,25 @@
|
|||||||
|
|
||||||
// ------------------------ Setup the OOP Wrapper: --------------------------
|
// ------------------------ Setup the OOP Wrapper: --------------------------
|
||||||
|
|
||||||
|
// If Underscore is called as a function, it returns a wrapped object that
|
||||||
|
// can be used OO-style. This wrapper holds altered versions of all the
|
||||||
|
// underscore functions. Wrapped objects may be chained.
|
||||||
|
var wrapper = function(obj) { this._wrapped = obj; };
|
||||||
|
|
||||||
// Helper function to continue chaining intermediate results.
|
// Helper function to continue chaining intermediate results.
|
||||||
var result = function(obj, chain) {
|
var result = function(obj, chain) {
|
||||||
return chain ? _(obj).chain() : obj;
|
return chain ? _(obj).chain() : obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A method to easily add functions to the OOP wrapper.
|
||||||
|
var addToWrapper = function(name, func) {
|
||||||
|
wrapper.prototype[name] = function() {
|
||||||
|
var args = _.toArray(arguments);
|
||||||
|
unshift.call(args, this._wrapped);
|
||||||
|
return result(func.apply(_, args), this._chain);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
// Add all of the Underscore functions to the wrapper object.
|
// Add all of the Underscore functions to the wrapper object.
|
||||||
_.mixin(_);
|
_.mixin(_);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user