diff --git a/lodash.js b/lodash.js index 71b373e886..2acccade0a 100644 --- a/lodash.js +++ b/lodash.js @@ -4672,14 +4672,17 @@ throw new TypeError; } } + var funcsLength = funcs.length; + if (funcsLength === 1) { + return funcs[0]; + } return function() { - var args = arguments, - length = funcs.length; - + var length = funcsLength - 1, + result = funcs[length].apply(this, arguments); while (length--) { - args = [funcs[length].apply(this, args)]; + result = funcs[length].call(this, result); } - return args[0]; + return result; }; } diff --git a/test/test.js b/test/test.js index bf73dd09e2..76bb54e4e7 100644 --- a/test/test.js +++ b/test/test.js @@ -1259,6 +1259,12 @@ var welcome = _.compose(greet, format); equal(welcome('pebbles'), 'Hiya Penelope!'); }); + + test('should return original function if only one function passed', 1, function(){ + var noop = function(){}; + equal(_.compose(noop), noop); + }); + }()); /*--------------------------------------------------------------------------*/