Make _.defaultsDeep and _.merge consistent with _.defaults in assigning undefined values. [closes #2676]

This commit is contained in:
John-David Dalton
2016-09-26 21:27:33 -07:00
parent c1c394ac60
commit b678bb4a74
2 changed files with 49 additions and 19 deletions

View File

@@ -2462,7 +2462,7 @@
*/
function assignMergeValue(object, key, value) {
if ((value !== undefined && !eq(object[key], value)) ||
(typeof key == 'number' && value === undefined && !(key in object))) {
(value === undefined && !(key in object))) {
baseAssignValue(object, key, value);
}
}
@@ -3616,29 +3616,32 @@
var isCommon = newValue === undefined;
if (isCommon) {
var isArr = isArray(srcValue),
isTyped = !isArr && isTypedArray(srcValue);
newValue = srcValue;
if (isArray(srcValue) || isTypedArray(srcValue)) {
if (isArr || isTyped) {
if (isArray(objValue)) {
newValue = objValue;
}
else if (isArrayLikeObject(objValue)) {
newValue = copyArray(objValue);
}
else {
else if (isTyped) {
isCommon = false;
newValue = baseClone(srcValue, true);
newValue = cloneTypedArray(srcValue, true);
}
else {
newValue = [];
}
}
else if (isPlainObject(srcValue) || isArguments(srcValue)) {
newValue = objValue;
if (isArguments(objValue)) {
newValue = toPlainObject(objValue);
}
else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
isCommon = false;
newValue = baseClone(srcValue, true);
}
else {
newValue = objValue;
newValue = initCloneObject(srcValue);
}
}
else {