标签:
let person = { firstName: "Zhentian", lastName: "Wan" }; /*Object.freeze() makes object cannot be updated, added or deleted*/ let freezePerson = Object.freeze(person); freezePerson.address="Finland"; // Cannot add property address, object is not extensiable. console.log(freezePerson.firstName); // Zhentian freezePerson.firstName = "John"; //Cannot assing to read only property ‘firstName‘ /*Seal, property can be udpated, but cannot be delted or added*/ let sealPerson = Object.seal(person); sealPerson.firstName = "Answer"; // works! console.log(sealPerson.firstName); sealPerson.address="Finland"; // Cannot add property address, object is not extensible console.log(sealPerson.address);
[Javascript] Object.freeze() vs Object.seal()
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5702064.html