From 82c7a22d275b53c760294b0c878a2fdc74f877b4 Mon Sep 17 00:00:00 2001 From: jdalton Date: Fri, 6 Feb 2015 22:45:58 -0800 Subject: [PATCH] Ensure `_.flow` and `_.flowRight` return an identity function when no arguments are provided. [closes #938] --- lodash.src.js | 4 ++-- test/test.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index c840b4aca..81d8bbd26 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -7207,7 +7207,7 @@ length = funcs.length; if (!length) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); @@ -7252,7 +7252,7 @@ fromIndex = funcs.length - 1; if (fromIndex < 0) { - return function() {}; + return function() { return arguments[0]; }; } if (!arrayEvery(funcs, isFunction)) { throw new TypeError(FUNC_ERROR_TEXT); diff --git a/test/test.js b/test/test.js index f1bfde13d..673a92ea1 100644 --- a/test/test.js +++ b/test/test.js @@ -2023,15 +2023,15 @@ notStrictEqual(func(_.noop), _.noop); }); - test('`_.' + methodName + '` should return a noop function when no arguments are provided', 2, function() { + test('`_.' + methodName + '` should return an identity function when no arguments are provided', 2, function() { var combined = func(); try { - strictEqual(combined(), undefined); + strictEqual(combined('a'), 'a'); } catch(e) { ok(false, e.message); } - notStrictEqual(combined, _.noop); + notStrictEqual(combined, _.identity); }); test('`_.' + methodName + '` should return a wrapped value when chaining', 1, function() {