diff --git a/lodash.js b/lodash.js index 5362a9c00..2101bb3c1 100644 --- a/lodash.js +++ b/lodash.js @@ -4247,7 +4247,9 @@ length -= holders.length; if (length < arity) { - return createRecurryWrapper(func, bitmask, createHybridWrapper, placeholder, undefined, args, holders, undefined, undefined, arity - length); + return createRecurryWrapper( + func, bitmask, createHybridWrapper, wrapper.placeholder, undefined, + args, holders, undefined, undefined, arity - length); } var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; return apply(fn, this, args); @@ -4364,8 +4366,8 @@ if (isCurried && length < arity) { var newHolders = replaceHolders(args, placeholder); return createRecurryWrapper( - func, bitmask, createHybridWrapper, placeholder, thisArg, args, - newHolders, argPos, ary, arity - length + func, bitmask, createHybridWrapper, wrapper.placeholder, thisArg, + args, newHolders, argPos, ary, arity - length ); } var thisBinding = isBind ? thisArg : this, @@ -8605,7 +8607,7 @@ function curry(func, arity, guard) { arity = guard ? undefined : arity; var result = createWrapper(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity); - result.placeholder = getPlaceholder(curry); + result.placeholder = curry.placeholder; return result; } @@ -8649,7 +8651,7 @@ function curryRight(func, arity, guard) { arity = guard ? undefined : arity; var result = createWrapper(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity); - result.placeholder = getPlaceholder(curryRight); + result.placeholder = curryRight.placeholder; return result; } diff --git a/test/test.js b/test/test.js index a934e5a09..d70abe7de 100644 --- a/test/test.js +++ b/test/test.js @@ -1715,6 +1715,23 @@ assert.deepEqual(bound(), [object, undefined, 'b', undefined]); }); + QUnit.test('should use `_.placeholder` when set', function(assert) { + assert.expect(1); + + if (!isModularize) { + var _ph = _.placeholder = {}, + ph = _.bind.placeholder, + object = {}, + bound = _.bind(fn, object, _ph, 'b', ph); + + assert.deepEqual(bound('a', 'c'), [object, 'a', 'b', ph, 'c']); + delete _.placeholder; + } + else { + skipAssert(assert); + } + }); + QUnit.test('should create a function with a `length` of `0`', function(assert) { assert.expect(2); @@ -1995,6 +2012,28 @@ assert.deepEqual(bound(), [undefined, 'b', undefined]); }); + QUnit.test('should use `_.placeholder` when set', function(assert) { + assert.expect(1); + + if (!isModularize) { + var object = { + 'fn': function() { + return slice.call(arguments); + } + }; + + var _ph = _.placeholder = {}, + ph = _.bindKey.placeholder, + bound = _.bindKey(object, 'fn', _ph, 'b', ph); + + assert.deepEqual(bound('a', 'c'), ['a', 'b', ph, 'c']); + delete _.placeholder; + } + else { + skipAssert(assert); + } + }); + QUnit.test('should ensure `new bound` is an instance of `object[key]`', function(assert) { assert.expect(2); @@ -3622,6 +3661,22 @@ assert.deepEqual(actual, ['a', 'b', 'c', 'd']); }); + QUnit.test('should use `_.placeholder` when set', function(assert) { + assert.expect(1); + + if (!isModularize) { + var curried = _.curry(fn), + _ph = _.placeholder = {}, + ph = curried.placeholder; + + assert.deepEqual(curried(1)(_ph, 3)(ph, 4), [1, ph, 3, 4]); + delete _.placeholder; + } + else { + skipAssert(assert); + } + }); + QUnit.test('should provide additional arguments after reaching the target arity', function(assert) { assert.expect(3); @@ -3765,6 +3820,22 @@ assert.deepEqual(actual, ['a', 'b', 'c', 'd']); }); + QUnit.test('should use `_.placeholder` when set', function(assert) { + assert.expect(1); + + if (!isModularize) { + var curried = _.curryRight(fn), + _ph = _.placeholder = {}, + ph = curried.placeholder; + + assert.deepEqual(curried(4)(2, _ph)(1, ph), [1, 2, ph, 4]); + delete _.placeholder; + } + else { + skipAssert(assert); + } + }); + QUnit.test('should provide additional arguments after reaching the target arity', function(assert) { assert.expect(3); @@ -15857,9 +15928,9 @@ var fn = function(a, b) { return [a, b]; }, par = func(fn, 'a'), - expected = ['a', 'b']; + expected = isPartial ? ['a', 'b'] : ['b', 'a']; - assert.deepEqual(par('b'), isPartial ? expected : expected.reverse()); + assert.deepEqual(par('b'), expected); }); QUnit.test('`_.' + methodName + '` works when there are no partially applied arguments and the created function is invoked without additional arguments', function(assert) { @@ -15896,6 +15967,23 @@ } }); + QUnit.test('`_.' + methodName + '` should use `_.placeholder` when set', function(assert) { + assert.expect(1); + + if (!isModularize) { + var _ph = _.placeholder = {}, + fn = function() { return slice.call(arguments); }, + par = func(fn, _ph, 'b', ph), + expected = isPartial ? ['a', 'b', ph, 'c'] : ['a', 'c', 'b', ph]; + + assert.deepEqual(par('a', 'c'), expected); + delete _.placeholder; + } + else { + skipAssert(assert); + } + }); + QUnit.test('`_.' + methodName + '` creates a function with a `length` of `0`', function(assert) { assert.expect(1);