Files
lodash/_copyObject.js
John-David Dalton 0b9ddff408 Bump to v4.16.0.
2016-09-17 22:24:52 -07:00

44 lines
1.2 KiB
JavaScript

define(['./_assignValue', './_baseAssignValue'], function(assignValue, baseAssignValue) {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* Copies properties of `source` to `object`.
*
* @private
* @param {Object} source The object to copy properties from.
* @param {Array} props The property identifiers to copy.
* @param {Object} [object={}] The object to copy properties to.
* @param {Function} [customizer] The function to customize copied values.
* @returns {Object} Returns `object`.
*/
function copyObject(source, props, object, customizer) {
var isNew = !object;
object || (object = {});
var index = -1,
length = props.length;
while (++index < length) {
var key = props[index];
var newValue = customizer
? customizer(object[key], source[key], key, object, source)
: undefined;
if (newValue === undefined) {
newValue = source[key];
}
if (isNew) {
baseAssignValue(object, key, newValue);
} else {
assignValue(object, key, newValue);
}
}
return object;
}
return copyObject;
});