1 var bindCallback = require('./bindCallback'),
2 isIterateeCall = require('./isIterateeCall'),
3 restParam = require('../function/restParam');
6 * Creates a function that assigns properties of source object(s) to a given
9 * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
12 * @param {Function} assigner The function to assign values.
13 * @returns {Function} Returns the new assigner function.
15 function createAssigner(assigner) {
16 return restParam(function(object, sources) {
18 length = object == null ? 0 : sources.length,
19 customizer = length > 2 && sources[length - 2],
20 guard = length > 2 && sources[2],
21 thisArg = length > 1 && sources[length - 1];
23 if (typeof customizer == 'function') {
24 customizer = bindCallback(customizer, thisArg, 5);
27 customizer = typeof thisArg == 'function' ? thisArg : null;
28 length -= (customizer ? 1 : 0);
30 if (guard && isIterateeCall(sources[0], sources[1], guard)) {
31 customizer = length < 3 ? null : customizer;
34 while (++index < length) {
35 var source = sources[index];
37 assigner(object, source, customizer);
44 module.exports = createAssigner;