SIGN IN SIGN UP

A modern JavaScript utility library delivering modularity, performance, & extras.

0 0 2037 JavaScript
2016-09-17 22:24:52 -07:00
define(['./_assignValue', './_baseAssignValue'], function(assignValue, baseAssignValue) {
2015-01-08 00:37:01 -08:00
2016-07-24 09:52:04 -07:00
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
2015-01-08 00:37:01 -08:00
/**
2015-12-16 17:49:35 -08:00
* Copies properties of `source` to `object`.
2015-01-08 00:37:01 -08:00
*
* @private
* @param {Object} source The object to copy properties from.
2016-03-26 00:00:01 -07:00
* @param {Array} props The property identifiers to copy.
2015-12-16 17:49:35 -08:00
* @param {Object} [object={}] The object to copy properties to.
2016-04-12 22:18:39 -07:00
* @param {Function} [customizer] The function to customize copied values.
2015-01-08 00:37:01 -08:00
* @returns {Object} Returns `object`.
*/
2016-04-12 22:18:39 -07:00
function copyObject(source, props, object, customizer) {
2016-09-17 22:24:52 -07:00
var isNew = !object;
2016-04-12 22:18:39 -07:00
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)
2016-07-24 09:52:04 -07:00
: undefined;
2016-04-12 22:18:39 -07:00
2016-09-17 22:24:52 -07:00
if (newValue === undefined) {
newValue = source[key];
}
if (isNew) {
baseAssignValue(object, key, newValue);
} else {
assignValue(object, key, newValue);
}
2016-04-12 22:18:39 -07:00
}
return object;
2015-01-08 00:37:01 -08:00
}
2015-12-16 17:53:20 -08:00
return copyObject;
2015-01-08 00:37:01 -08:00
});