From cca4c4be8087a86e819b48aacbbfba57fdce956e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sun, 16 Dec 2012 00:14:00 -0800 Subject: [PATCH] Fix `hasObjectSpliceBug` implementations of `_#pop`, `_#shift`, and `_#splice`. Former-commit-id: 91a3bc259c85bd269c3d895b66204bdc4d158827 --- lodash.js | 10 ++++++---- test/underscore.html | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lodash.js b/lodash.js index 1238359ff..69550026b 100644 --- a/lodash.js +++ b/lodash.js @@ -4399,16 +4399,18 @@ // avoid array-like object bugs with `Array#shift` and `Array#splice` // in Firefox < 10 and IE < 9 if (hasObjectSpliceBug) { - each(['shift', 'splice'], function(methodName) { - var func = lodash.prototype[methodName]; + each(['pop', 'shift', 'splice'], function(methodName) { + var func = arrayRef[methodName], + isSplice = methodName == 'splice'; + lodash.prototype[methodName] = function() { var value = this.__wrapped__, - result = func.apply(this, arguments); + result = func.apply(value, arguments); if (value.length === 0) { delete value[0]; } - return result; + return isSplice ? new lodash(result) : result; }; }); } diff --git a/test/underscore.html b/test/underscore.html index 62c954e4b..564c77a1f 100644 --- a/test/underscore.html +++ b/test/underscore.html @@ -34,8 +34,11 @@