mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Add baseCopy.
This commit is contained in:
committed by
jdalton
parent
fb2a20201c
commit
d70b5a9886
@@ -1408,7 +1408,7 @@
|
|||||||
* Copies the values of `array` to `other`.
|
* Copies the values of `array` to `other`.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Array} array The array to copy.
|
* @param {Array} array The array to copy values from.
|
||||||
* @param {Array} [other=[]] The array to copy values to.
|
* @param {Array} [other=[]] The array to copy values to.
|
||||||
* @returns {Array} Returns `other`.
|
* @returns {Array} Returns `other`.
|
||||||
*/
|
*/
|
||||||
@@ -1684,22 +1684,21 @@
|
|||||||
* @returns {Object} Returns the destination object.
|
* @returns {Object} Returns the destination object.
|
||||||
*/
|
*/
|
||||||
function baseAssign(object, source, customizer) {
|
function baseAssign(object, source, customizer) {
|
||||||
|
var props = keys(source);
|
||||||
|
if (!customizer) {
|
||||||
|
return baseCopy(source, object, props);
|
||||||
|
}
|
||||||
var index = -1,
|
var index = -1,
|
||||||
props = keys(source),
|
length = props.length
|
||||||
length = props.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
while (++index < length) {
|
||||||
var key = props[index];
|
var key = props[index],
|
||||||
if (customizer) {
|
value = object[key],
|
||||||
var value = object[key],
|
result = customizer(value, source[key], key, object, source);
|
||||||
result = customizer(value, source[key], key, object, source);
|
|
||||||
|
|
||||||
if ((result === result ? result !== value : value === value) ||
|
if ((result === result ? result !== value : value === value) ||
|
||||||
(typeof value == 'undefined' && !(key in object))) {
|
(typeof value == 'undefined' && !(key in object))) {
|
||||||
object[key] = result;
|
object[key] = result;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
object[key] = source[key];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
@@ -1733,6 +1732,30 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies the properties of `object` to `other`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Object} object The object to copy properties from.
|
||||||
|
* @param {Object} [other={}] The object to copy properties to.
|
||||||
|
* @param {Array} props The property names to copy.
|
||||||
|
* @returns {Object} Returns `other`.
|
||||||
|
*/
|
||||||
|
function baseCopy(object, other, props) {
|
||||||
|
if (!props) {
|
||||||
|
props = other;
|
||||||
|
other = {};
|
||||||
|
}
|
||||||
|
var index = -1,
|
||||||
|
length = props.length;
|
||||||
|
|
||||||
|
while (++index < length) {
|
||||||
|
var key = props[index];
|
||||||
|
other[key] = object[key];
|
||||||
|
}
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base implementation of `_.bindAll` without support for individual
|
* The base implementation of `_.bindAll` without support for individual
|
||||||
* method name arguments.
|
* method name arguments.
|
||||||
|
|||||||
Reference in New Issue
Block a user