深拷贝-浅拷贝-引用赋值的关系
<script>
const info ={
name:"hdc",
age:21,
friends:{
name:"kobe"
}
}
//1.引用赋值
const obj1 = info
// 2.操作二:浅拷贝
const obj2 = {...info}
//obj2.name = "james"
//obj2.friend.name = "james"
// console.log(info.friends.name)
const obj3 = Object.assign({},info)
//obj3.name = "curry"
obj3.friends.name = "curry"
console.log(info.friends.name)
// 3,操作三:深拷贝
//1.JSON方法实现深拷贝
const obj4 = JSON.parse(JSON.stringify(info))
//特殊的值是无能为力的
//2.自己编写深拷贝函数(第三方库)
</script>

浙公网安备 33010602011771号