From f0f23d491cae12d6a1e361c3c3a64e8d36870b54 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 9 Aug 2013 09:08:23 -0700 Subject: [PATCH] Cleanup `_.curry`. Former-commit-id: edcc8b2b4c67fa04d8c67e7b7fcdd071c4155e89 --- lodash.js | 5 +++-- test/test.js | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lodash.js b/lodash.js index a1f861a38..cfbcd3f9d 100644 --- a/lodash.js +++ b/lodash.js @@ -1445,6 +1445,7 @@ var isBind = bitmask & 1, isBindKey = bitmask & 2, isCurry = bitmask & 4, + isPartial = bitmask & 8, isPartialRight = bitmask & 16; if (!isBindKey && !isFunction(func)) { @@ -1458,10 +1459,10 @@ if (isCurry && !(bindData[1] & 4)) { bindData[5] = arity; } - if (partialArgs) { + if (isPartial) { push.apply(bindData[2] || (bindData[2] = []), partialArgs); } - if (partialRightArgs) { + if (isPartialRight) { push.apply(bindData[3] || (bindData[3] = []), partialRightArgs); } bindData[1] |= bitmask; diff --git a/test/test.js b/test/test.js index 0022e7d10..5ba98959b 100644 --- a/test/test.js +++ b/test/test.js @@ -679,6 +679,20 @@ equal(curried(1, 2, 3), 6); }); + test('should work with partial methods', function() { + function func(a, b, c) { + return a + b + c; + } + + var curried = _.curry(func), + a = _.partial(curried, 1), + b = _.partialRight(a, 3), + c = _.partialRight(a(2), 3); + + equal(b(2), 6); + equal(c(), 6); + }); + test('should not alter the `this` binding', function() { function func(a, b, c) { return this[a] + this[b] + this[c];