mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +00:00
36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
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;
|
|
});
|