diff --git a/underscore.js b/underscore.js index a445cdcb0..5e0297322 100644 --- a/underscore.js +++ b/underscore.js @@ -30,28 +30,29 @@ // Export the Underscore object for CommonJS. if (typeof exports !== 'undefined') exports._ = _; + // Save bytes in the minified (but not gzipped) version: + var ArrayPrototype = Array.prototype; + // Create quick reference variables for speed access to core prototypes. - var slice = Array.prototype.slice, - unshift = Array.prototype.unshift, + var slice = ArrayPrototype.slice, + unshift = ArrayPrototype.unshift, toString = Object.prototype.toString, hasOwnProperty = Object.prototype.hasOwnProperty, propertyIsEnumerable = Object.prototype.propertyIsEnumerable; - // All native implementations we hope to use are declared here, - // mostly Array.prototype methods. - // + // All native implementations we hope to use are declared here. // 'native' is on the long list of reserved words. // Ok to use as a property name, though jsLint doesn't agree. var Native = _['native'] = { - forEach: Array.prototype.forEach, - map: Array.prototype.map, - reduce: Array.prototype.reduce, - reduceRight: Array.prototype.reduceRight, - filter: Array.prototype.filter, - every: Array.prototype.every, - some: Array.prototype.some, - indexOf: Array.prototype.indexOf, - lastIndexOf: Array.prototype.lastIndexOf, + forEach: ArrayPrototype.forEach, + map: ArrayPrototype.map, + reduce: ArrayPrototype.reduce, + reduceRight: ArrayPrototype.reduceRight, + filter: ArrayPrototype.filter, + every: ArrayPrototype.every, + some: ArrayPrototype.some, + indexOf: ArrayPrototype.indexOf, + lastIndexOf: ArrayPrototype.lastIndexOf, isArray: Array.isArray, keys: Object.keys }; @@ -688,7 +689,7 @@ // Add all mutator Array functions to the wrapper. each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { - var method = Array.prototype[name]; + var method = ArrayPrototype[name]; wrapper.prototype[name] = function() { method.apply(this._wrapped, arguments); return result(this._wrapped, this._chain); @@ -697,7 +698,7 @@ // Add all accessor Array functions to the wrapper. each(['concat', 'join', 'slice'], function(name) { - var method = Array.prototype[name]; + var method = ArrayPrototype[name]; wrapper.prototype[name] = function() { return result(method.apply(this._wrapped, arguments), this._chain); };