冻结对象:
var pizza = { name: 'Peri Peri', Topping: 'Prawn' }; Object.freeze(pizza); // Can't change the name of the object because it's frozen pizza.name = 'Hawaiian';
解冻对象:
var pizza = { name: 'Peri Peri', Topping: 'Prawn' }; Object.freeze(pizza); pizza.name = 'Hawaiian'; console.log(pizza); // { name: 'Peri Peri', Topping: 'Prawn' } pizza = JSON.parse(JSON.stringify(pizza)); // Clones the object pizza.name = 'Hawaiian'; console.log(pizza); // { name: 'Hawaiian', Topping: 'Prawn' }