话不多说,直接上代码
export function MergeRecursive(obj1, obj2) {
let arr = Object.keys(obj2);
let index = -1;
while (++index < arr.length) {
let p = arr[index];
try {
if (obj2[p].constructor == Object) {
obj1[p] = MergeRecursive(obj1[p], obj2[p]);
} else {
obj1[p] = obj2[p];
}
} catch (e) {
obj1[p] = obj2[p];
}
}
return obj1;
}
网友评论