冻结对象与解冻对象

冻结对象:

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' }

 

上一篇:[LeetCode] 1774. Closest Dessert Cost


下一篇:python参数:*和**