mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
cache wrapper methods
This commit is contained in:
@@ -555,24 +555,28 @@
|
|||||||
|
|
||||||
// Add all of the Underscore functions to the wrapper object.
|
// Add all of the Underscore functions to the wrapper object.
|
||||||
_.each(_.functions(_), function(name) {
|
_.each(_.functions(_), function(name) {
|
||||||
|
var unshift = Array.prototype.unshift,
|
||||||
|
method = _[name];
|
||||||
wrapper.prototype[name] = function() {
|
wrapper.prototype[name] = function() {
|
||||||
Array.prototype.unshift.call(arguments, this._wrapped);
|
unshift.call(arguments, this._wrapped);
|
||||||
return result(_[name].apply(_, arguments), this._chain);
|
return result(method.apply(_, arguments), this._chain);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add all mutator Array functions to the wrapper.
|
// Add all mutator Array functions to the wrapper.
|
||||||
_.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
_.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
|
||||||
|
var method = Array.prototype[name];
|
||||||
wrapper.prototype[name] = function() {
|
wrapper.prototype[name] = function() {
|
||||||
Array.prototype[name].apply(this._wrapped, arguments);
|
method.apply(this._wrapped, arguments);
|
||||||
return result(this._wrapped, this._chain);
|
return result(this._wrapped, this._chain);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add all accessor Array functions to the wrapper.
|
// Add all accessor Array functions to the wrapper.
|
||||||
_.each(['concat', 'join', 'slice'], function(name) {
|
_.each(['concat', 'join', 'slice'], function(name) {
|
||||||
|
var method = Array.prototype[name];
|
||||||
wrapper.prototype[name] = function() {
|
wrapper.prototype[name] = function() {
|
||||||
return result(Array.prototype[name].apply(this._wrapped, arguments), this._chain);
|
return result(method.apply(this._wrapped, arguments), this._chain);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user