diff --git a/lodash.js b/lodash.js index 60abd2d6f..3857f433b 100644 --- a/lodash.js +++ b/lodash.js @@ -1588,6 +1588,7 @@ } var bindData = func && func.__bindData__; if (bindData && bindData !== true) { + bindData = nativeSlice.call(bindData); if (isBind && !(bindData[1] & 1)) { bindData[4] = thisArg; } diff --git a/test/test.js b/test/test.js index 1f10f1922..dfab68ea8 100644 --- a/test/test.js +++ b/test/test.js @@ -436,6 +436,26 @@ test('should throw a TypeError if `func` is not a function', 1, function() { raises(function() { _.bind(); }, TypeError); }); + + test('should rebind functions correctly', 3, function() { + function func() { + var args = [this]; + push.apply(args, arguments); + return args; + } + + var object1 = {}, + object2 = {}, + object3 = {}; + + var bound1 = _.bind(func, object1), + bound2 = _.bind(bound1, object2, 'a'), + bound3 = _.bind(bound1, object3, 'b'); + + deepEqual(bound1(), [object1]); + deepEqual(bound2(), [object1, 'a']); + deepEqual(bound3(), [object1, 'b']); + }); }()); /*--------------------------------------------------------------------------*/