Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / internal / createAssigner.js
1 var bindCallback = require('./bindCallback'),
2     isIterateeCall = require('./isIterateeCall'),
3     restParam = require('../function/restParam');
4
5 /**
6  * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
7  *
8  * @private
9  * @param {Function} assigner The function to assign values.
10  * @returns {Function} Returns the new assigner function.
11  */
12 function createAssigner(assigner) {
13   return restParam(function(object, sources) {
14     var index = -1,
15         length = object == null ? 0 : sources.length,
16         customizer = length > 2 ? sources[length - 2] : undefined,
17         guard = length > 2 ? sources[2] : undefined,
18         thisArg = length > 1 ? sources[length - 1] : undefined;
19
20     if (typeof customizer == 'function') {
21       customizer = bindCallback(customizer, thisArg, 5);
22       length -= 2;
23     } else {
24       customizer = typeof thisArg == 'function' ? thisArg : undefined;
25       length -= (customizer ? 1 : 0);
26     }
27     if (guard && isIterateeCall(sources[0], sources[1], guard)) {
28       customizer = length < 3 ? undefined : customizer;
29       length = 1;
30     }
31     while (++index < length) {
32       var source = sources[index];
33       if (source) {
34         assigner(object, source, customizer);
35       }
36     }
37     return object;
38   });
39 }
40
41 module.exports = createAssigner;