代码
function depClone(obj) {
var result = JSON.parse(JSON.stringify(obj));
return result;
}
var obj = {
family: {
brother: “wangzhipeng”,
father: “wanglicai”,
mother: “sunaiyun”
},
name: “gino”,
sex: “male”,
age: “27”
};
var obj1 = depClone(obj)
obj1.family.border = ‘aa’
console.log(obj) // 原对象没有改变
console.log(obj1) // 新对象有改变
效果