mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
34 lines
931 B
JavaScript
34 lines
931 B
JavaScript
define(['./_assignValue'], function(assignValue) {
|
|
|
|
/**
|
|
* This function is like `copyObject` except that it accepts a function to
|
|
* customize copied values.
|
|
*
|
|
* @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 copyObjectWith(source, props, object, customizer) {
|
|
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)
|
|
: source[key];
|
|
|
|
assignValue(object, key, newValue);
|
|
}
|
|
return object;
|
|
}
|
|
|
|
return copyObjectWith;
|
|
});
|