From 2adac8bdaed7e61fc5bf11e2ce41b989793cdc53 Mon Sep 17 00:00:00 2001 From: jdalton Date: Wed, 1 Apr 2015 01:26:27 -0700 Subject: [PATCH] Use `_.restParam` in `createAssigner`. --- lodash.src.js | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/lodash.src.js b/lodash.src.js index 8ab4bb4ec..84f50b2e4 100644 --- a/lodash.src.js +++ b/lodash.src.js @@ -3207,38 +3207,32 @@ * @returns {Function} Returns the new assigner function. */ function createAssigner(assigner) { - return function() { - var args = arguments, - length = args.length, - object = args[0]; + return restParam(function(object, sources) { + var index = -1, + length = object == null ? 0 : sources.length, + customizer = sources[length - 2], + thisArg = sources[length - 1], + guard = sources[2]; - if (length < 2 || object == null) { - return object; - } - var customizer = args[length - 2], - thisArg = args[length - 1], - guard = args[3]; - - if (length > 3 && typeof customizer == 'function') { + if (length > 2 && typeof customizer == 'function') { customizer = bindCallback(customizer, thisArg, 5); length -= 2; - } else { - customizer = (length > 2 && typeof thisArg == 'function') ? thisArg : null; + } else if (length > 1) { + customizer = typeof thisArg == 'function' ? thisArg : null; length -= (customizer ? 1 : 0); } - if (guard && isIterateeCall(args[1], args[2], guard)) { - customizer = length == 3 ? null : customizer; - length = 2; + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? null : customizer; + length = 1; } - var index = 0; while (++index < length) { - var source = args[index]; + var source = sources[index]; if (source) { assigner(object, source, customizer); } } return object; - }; + }); } /**