From 39024c35a62c1e8045f064447409f226f759647f Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Wed, 24 Feb 2010 12:03:08 -0500 Subject: [PATCH] waypoint commit on the big merge --- underscore.js | 98 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 50 deletions(-) diff --git a/underscore.js b/underscore.js index 25bafb556..19836ebc3 100644 --- a/underscore.js +++ b/underscore.js @@ -20,49 +20,49 @@ // Quick regexp-escaping function, because JS doesn't have RegExp.escape(). var escapeRegExp = function(s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1'); }; - + // Save bytes in the minified (but not gzipped) version: - var Array_Prototype = Array.prototype; - + var ArrayProto = Array.prototype, ObjProto = Object.prototype; + // Create quick reference variables for speed access to core prototypes. - var slice = Array_Prototype.slice, - unshift = Array_Prototype.unshift, - toString = Object.prototype.toString, - hasOwnProperty = Object.prototype.hasOwnProperty, - propertyIsEnumerable = Object.prototype.propertyIsEnumerable; + var slice = ArrayProto.slice, + unshift = ArrayProto.unshift, + toString = ObjProto.toString, + hasOwnProperty = ObjProto.hasOwnProperty, + propertyIsEnumerable = ObjProto.propertyIsEnumerable; // All native implementations we hope to use are declared here. - var - native_forEach = Array_Prototype.forEach, - native_map = Array_Prototype.map, - native_reduce = Array_Prototype.reduce, - native_reduceRight = Array_Prototype.reduceRight, - native_filter = Array_Prototype.filter, - native_every = Array_Prototype.every, - native_some = Array_Prototype.some, - native_indexOf = Array_Prototype.indexOf, - native_lastIndexOf = Array_Prototype.lastIndexOf, + var + native_forEach = ArrayProto.forEach, + native_map = ArrayProto.map, + native_reduce = ArrayProto.reduce, + native_reduceRight = ArrayProto.reduceRight, + native_filter = ArrayProto.filter, + native_every = ArrayProto.every, + native_some = ArrayProto.some, + native_indexOf = ArrayProto.indexOf, + native_lastIndexOf = ArrayProto.lastIndexOf, native_isArray = Array['isArray'], // use [] notation since not in closure's externs native_keys = Object['keys']; - + // Create a safe reference to the Underscore object for reference below. - var _ = function(obj) { return _.buildWrapper(obj) }; + var _ = function(obj) { return _.buildWrapper(obj); }; // Export the Underscore object for CommonJS. if (typeof exports !== 'undefined') exports._ = _; // Export underscore to global scope. root._ = _; - + // Current version. _.VERSION = '0.5.8'; - + // ------------------------ Collection Functions: --------------------------- // The cornerstone, an each implementation. // Handles objects implementing forEach, arrays, and raw objects. // Delegates to JavaScript 1.6's native forEach if available. - var each = + var each = _.forEach = function(obj, iterator, context) { var index = 0; try { @@ -71,11 +71,9 @@ } else if (_.isNumber(obj.length)) { for (var i=0, l=obj.length; i