-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathcreateAssigner.js
40 lines (37 loc) · 1.19 KB
/
createAssigner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
define(['./bindCallback', './isIterateeCall'], function(bindCallback, isIterateeCall) {
/**
* Creates a function that assigns properties of source object(s) to a given
* destination object.
*
* @private
* @param {Function} assigner The function to assign values.
* @returns {Function} Returns the new assigner function.
*/
function createAssigner(assigner) {
return function() {
var length = arguments.length,
object = arguments[0];
if (length < 2 || object == null) {
return object;
}
if (length > 3 && isIterateeCall(arguments[1], arguments[2], arguments[3])) {
length = 2;
}
// Juggle arguments.
if (length > 3 && typeof arguments[length - 2] == 'function') {
var customizer = bindCallback(arguments[--length - 1], arguments[length--], 5);
} else if (length > 2 && typeof arguments[length - 1] == 'function') {
customizer = arguments[--length];
}
var index = 0;
while (++index < length) {
var source = arguments[index];
if (source) {
assigner(object, source, customizer);
}
}
return object;
};
}
return createAssigner;
});