From 38cae13d692bd57c23ff31604c433124f8125af9 Mon Sep 17 00:00:00 2001 From: Noah Sloan Date: Tue, 8 Dec 2009 14:21:05 -0600 Subject: [PATCH] cache wrapper methods --- underscore.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/underscore.js b/underscore.js index b94cc0f9b..81898d4af 100644 --- a/underscore.js +++ b/underscore.js @@ -555,24 +555,28 @@ // Add all of the Underscore functions to the wrapper object. _.each(_.functions(_), function(name) { + var unshift = Array.prototype.unshift, + method = _[name]; wrapper.prototype[name] = function() { - Array.prototype.unshift.call(arguments, this._wrapped); - return result(_[name].apply(_, arguments), this._chain); + unshift.call(arguments, this._wrapped); + return result(method.apply(_, arguments), this._chain); }; }); // Add all mutator Array functions to the wrapper. _.each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { + var method = Array.prototype[name]; wrapper.prototype[name] = function() { - Array.prototype[name].apply(this._wrapped, arguments); + method.apply(this._wrapped, arguments); return result(this._wrapped, this._chain); }; }); // Add all accessor Array functions to the wrapper. _.each(['concat', 'join', 'slice'], function(name) { + var method = Array.prototype[name]; wrapper.prototype[name] = function() { - return result(Array.prototype[name].apply(this._wrapped, arguments), this._chain); + return result(method.apply(this._wrapped, arguments), this._chain); }; });