diff --git a/lodash.js b/lodash.js index 4d7d767ad..bc2a0d6fa 100644 --- a/lodash.js +++ b/lodash.js @@ -1624,7 +1624,7 @@ */ function baseCurry(func, bitmask, arity) { if (typeof arity != 'number') { - arity = +arity || (func ? func.length : 0); + arity = arity == null ? (func ? func.length : 0) : (+arity || 0); } return createWrapper([func, bitmask, arity]); } diff --git a/test/test.js b/test/test.js index 61e9e4130..4e05ca41c 100644 --- a/test/test.js +++ b/test/test.js @@ -2229,7 +2229,7 @@ deepEqual(curried(1, 2, 3, 4), expected); }); - test('should allow specifying `arity`', 3, function(){ + test('should allow specifying `arity`', 3, function() { var curried = _.curry(fn, 3), expected = [1, 2, 3]; @@ -2238,6 +2238,21 @@ deepEqual(curried(1, 2, 3), expected); }); + test('should coerce `arity` to a number', 2, function() { + var values = ['0', 'xyz'], + expected = _.map(values, _.constant([])); + + var actual = _.map(values, function(arity) { + var curried = _.curry(fn, arity); + return curried(); + }); + + deepEqual(actual, expected); + + curried = _.curry(fn, '2'); + deepEqual(curried(1)(2), [1, 2]); + }); + test('should work with partialed methods', 2, function() { var curried = _.curry(fn), expected = [1, 2, 3, 4];