-
Notifications
You must be signed in to change notification settings - Fork 7.1k
/
Copy pathbaseAssign.js
35 lines (31 loc) · 1.06 KB
/
baseAssign.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
define(['./baseCopy', '../object/keys'], function(baseCopy, keys) {
/**
* The base implementation of `_.assign` without support for argument juggling,
* multiple sources, and `this` binding `customizer` functions.
*
* @private
* @param {Object} object The destination object.
* @param {Object} source The source object.
* @param {Function} [customizer] The function to customize assigning values.
* @returns {Object} Returns the destination object.
*/
function baseAssign(object, source, customizer) {
var props = keys(source);
if (!customizer) {
return baseCopy(source, object, props);
}
var index = -1,
length = props.length
while (++index < length) {
var key = props[index],
value = object[key],
result = customizer(value, source[key], key, object, source);
if ((result === result ? result !== value : value === value) ||
(typeof value == 'undefined' && !(key in object))) {
object[key] = result;
}
}
return object;
}
return baseAssign;
});