mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-12 20:07:49 +00:00
make a local variable that points to Array.prototype since the former is not min'd down.
Won't effect gzip size, but reduces min size. Saves about: 15 bytes per instance * 13 instances ≅ 200 bytes
This commit is contained in:
@@ -30,28 +30,29 @@
|
|||||||
// Export the Underscore object for CommonJS.
|
// Export the Underscore object for CommonJS.
|
||||||
if (typeof exports !== 'undefined') exports._ = _;
|
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.
|
// Create quick reference variables for speed access to core prototypes.
|
||||||
var slice = Array.prototype.slice,
|
var slice = ArrayPrototype.slice,
|
||||||
unshift = Array.prototype.unshift,
|
unshift = ArrayPrototype.unshift,
|
||||||
toString = Object.prototype.toString,
|
toString = Object.prototype.toString,
|
||||||
hasOwnProperty = Object.prototype.hasOwnProperty,
|
hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||||
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
propertyIsEnumerable = Object.prototype.propertyIsEnumerable;
|
||||||
|
|
||||||
// All native implementations we hope to use are declared here,
|
// All native implementations we hope to use are declared here.
|
||||||
// mostly Array.prototype methods.
|
|
||||||
//
|
|
||||||
// 'native' is on the long list of reserved words.
|
// 'native' is on the long list of reserved words.
|
||||||
// Ok to use as a property name, though jsLint doesn't agree.
|
// Ok to use as a property name, though jsLint doesn't agree.
|
||||||
var Native = _['native'] = {
|
var Native = _['native'] = {
|
||||||
forEach: Array.prototype.forEach,
|
forEach: ArrayPrototype.forEach,
|
||||||
map: Array.prototype.map,
|
map: ArrayPrototype.map,
|
||||||
reduce: Array.prototype.reduce,
|
reduce: ArrayPrototype.reduce,
|
||||||
reduceRight: Array.prototype.reduceRight,
|
reduceRight: ArrayPrototype.reduceRight,
|
||||||
filter: Array.prototype.filter,
|
filter: ArrayPrototype.filter,
|
||||||
every: Array.prototype.every,
|
every: ArrayPrototype.every,
|
||||||
some: Array.prototype.some,
|
some: ArrayPrototype.some,
|
||||||
indexOf: Array.prototype.indexOf,
|
indexOf: ArrayPrototype.indexOf,
|
||||||
lastIndexOf: Array.prototype.lastIndexOf,
|
lastIndexOf: ArrayPrototype.lastIndexOf,
|
||||||
isArray: Array.isArray,
|
isArray: Array.isArray,
|
||||||
keys: Object.keys
|
keys: Object.keys
|
||||||
};
|
};
|
||||||
@@ -688,7 +689,7 @@
|
|||||||
|
|
||||||
// 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];
|
var method = ArrayPrototype[name];
|
||||||
wrapper.prototype[name] = function() {
|
wrapper.prototype[name] = function() {
|
||||||
method.apply(this._wrapped, arguments);
|
method.apply(this._wrapped, arguments);
|
||||||
return result(this._wrapped, this._chain);
|
return result(this._wrapped, this._chain);
|
||||||
@@ -697,7 +698,7 @@
|
|||||||
|
|
||||||
// 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];
|
var method = ArrayPrototype[name];
|
||||||
wrapper.prototype[name] = function() {
|
wrapper.prototype[name] = function() {
|
||||||
return result(method.apply(this._wrapped, arguments), this._chain);
|
return result(method.apply(this._wrapped, arguments), this._chain);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user