43593f06d130ae05bae018a523dcd11e1668d825
[platform/framework/web/crosswalk-tizen.git] /
1 var bindCallback = require('./bindCallback'),
2     isIterateeCall = require('./isIterateeCall'),
3     restParam = require('../function/restParam');
4
5 /**
6  * Creates a function that assigns properties of source object(s) to a given
7  * destination object.
8  *
9  * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`.
10  *
11  * @private
12  * @param {Function} assigner The function to assign values.
13  * @returns {Function} Returns the new assigner function.
14  */
15 function createAssigner(assigner) {
16   return restParam(function(object, sources) {
17     var index = -1,
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];
22
23     if (typeof customizer == 'function') {
24       customizer = bindCallback(customizer, thisArg, 5);
25       length -= 2;
26     } else {
27       customizer = typeof thisArg == 'function' ? thisArg : null;
28       length -= (customizer ? 1 : 0);
29     }
30     if (guard && isIterateeCall(sources[0], sources[1], guard)) {
31       customizer = length < 3 ? null : customizer;
32       length = 1;
33     }
34     while (++index < length) {
35       var source = sources[index];
36       if (source) {
37         assigner(object, source, customizer);
38       }
39     }
40     return object;
41   });
42 }
43
44 module.exports = createAssigner;