Opposite of Object.freeze or Object.seal in JavaScript

前端 未结 9 1364
无人共我
无人共我 2020-12-02 21:41

What is the opposite of Object.freeze or Object.seal? Is there a function that has a name such as detach?

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-02 22:36

    A little late to the party, but you can also create an object in a mutable variable (let), and reassign the original object to the variable when you need to reset it.

    For example:

    let obj = { objProp: "example" };
    
    if (condition) {
        Object.freeze(obj);
    }
    else {
        obj = { objProp: "example" };
    }
    

提交回复
热议问题