JS防止篡改对象的三种方法
1.锁定对象,不可扩展的对象,但可删除 Object.preventExtensions
const test = { name: 'james' };
Object.preventExtensions(test);
test.age = 40;
console.log(test.age); //undefined
2.密封对象 ,不可扩展的状态,也不可删除 Object.seal()
const test = { name: 'wang' };
Object.seal(test);
delete test.name;
console.log(test.name); //wang