From b38cf204f73ed10ef37b9392bddf2214b0942df7 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 1 Feb 2016 00:08:51 -0800 Subject: [PATCH] Add `start` param to `_.spread`. --- lodash.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index 14bf878d5..412490972 100644 --- a/lodash.js +++ b/lodash.js @@ -9039,6 +9039,7 @@ * @memberOf _ * @category Function * @param {Function} func The function to spread arguments over. + * @param {number} [start=0] The start position of the spread. * @returns {Function} Returns the new function. * @example * @@ -9059,13 +9060,20 @@ * })); * // => a Promise of 76 */ - function spread(func) { + function spread(func, start) { if (typeof func != 'function') { throw new TypeError(FUNC_ERROR_TEXT); } - return function(array) { - return apply(func, this, array); - }; + start = start === undefined ? 0 : nativeMax(toInteger(start), 0); + return rest(function(args) { + var array = args[start], + spreadArgs = args.slice(0, start); + + if (array) { + arrayPush(spreadArgs, array); + } + return apply(func, this, spreadArgs); + }); } /**