乐趣区

关于javascript:对象深层次拷贝

// 对象深拷贝 - 改进型, 如果某一对象节点值不是对象,则间接笼罩被合并对象值
export const objDeepMerge = (obj1, obj2) => {
let key;
for (key in obj2) {

obj1[key] =
  obj1[key] &&
  obj1[key].toString() === "[object Object]" &&
  (obj2[key] && obj2[key].toString() === "[object Object]")
    ? objDeepMerge(obj1[key], obj2[key])
    : (obj1[key] = obj2[key]);

}
return obj1;
}

退出移动版