From 2c5661ebb30461d7a004372318617ded7a332ae7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Tue, 6 Dec 2011 01:16:56 -0500 Subject: [PATCH] underscore: Avoid regression and cleanup comments. [jddalton] --- test/objects.js | 2 +- underscore.js | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/test/objects.js b/test/objects.js index 5edea3710..73c56376d 100644 --- a/test/objects.js +++ b/test/objects.js @@ -262,7 +262,7 @@ $(document).ready(function($, undefined) { ok(!_.isEqual({a: 1}, {a: 1, b: 2}), "Commutative equality is implemented for objects"); ok(!_.isEqual({x: 1, y: undefined}, {x: 1, z: 2}), "Objects with identical keys and different values are not equivalent"); - // Objects with shadowing properties + // Objects with properties that shadow non-enumerable ones. ok(!_.isEqual({}, {toString: 1}), "Object with custom toString is not equal to {}"); ok(_.isEqual({toString: 1, valueOf: 2}, {toString: 1, valueOf: 2}), "Objects with equivalent shadow properties"); diff --git a/underscore.js b/underscore.js index c6587c99b..34fd319d5 100644 --- a/underscore.js +++ b/underscore.js @@ -25,8 +25,8 @@ // Create quick reference variables for speed access to core prototypes. var concat = ArrayProto.concat, + push = ArrayProto.push, slice = ArrayProto.slice, - unshift = ArrayProto.unshift, toString = ObjProto.toString, hasOwnProperty = ObjProto.hasOwnProperty; @@ -85,7 +85,7 @@ var i = -1; var l = obj.length; - // We optimized for common use by only binding a context when it's passed + // We optimize for common use by only binding a context when it's passed. if (context) { iterator = function() { return fn.call(context, obj[i], i, obj); }; } @@ -100,7 +100,7 @@ } }; - // A simple each, for dealing with non-sparse arrays and arguments objects + // A simple each, for dealing with non-sparse arrays and arguments objects. var simpleEach = function(obj, iterator, index) { index || (index = 0); for (var l = obj.length; index < l; index++) { @@ -114,7 +114,7 @@ 'toLocaleString', 'toString', 'valueOf' ]; - // IE < 9 makes properties, shadowing non-enumerable ones, non-enumerable too + // IE < 9 makes properties, shadowing non-enumerable ones, non-enumerable too. var forShadowed = !{valueOf:0}.propertyIsEnumerable('valueOf') && function(obj, iterator) { // Because IE < 9 can't set the `[[Enumerable]]` attribute of an existing @@ -1021,8 +1021,9 @@ // A method to easily add functions to the OOP wrapper. var addToWrapper = function(name, func) { wrapper.prototype[name] = function() { - unshift.call(arguments, this._wrapped); - return result(func.apply(_, arguments), this._chain); + var args = [this._wrapped]; + push.apply(args, arguments); + return result(func.apply(_, args), this._chain); }; };