const box = { x: 10, y: 20 ,a:{age:18}};
Object.freeze(box); //Object.freeze使得无法添加、删除或修改对象的属性(除非属性的值是另一个对象)
const shape = box;//只是赋值了引用地址,当age变化的时候,俩变量中的age都会变
console.log(Object.isFrozen(box))//true 检查一个对象是否被冻结
shape.x = 100;
shape.a.age = 28;
console.log(box)//{x: 10, y: 20, a: {age:28}}
console.log(shape)//{x: 10, y: 20, a: {age:28}}
// 其实只能冻结第一层,
11-16
5017
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-24
7695
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)