Opposite of Object.freeze or Object.seal in JavaScript

I think you can do, using some tricks:

  • First create a duplicate temporary variable of original object
  • then set the original variable to undefined
  • the reset the value of it from the temporary.

Code here:

var obj = {a : 5};

console.log(obj); // {a: 5}
Object.freeze(obj);

obj.b = 10; // trying to add something to obj var
console.log(obj); // output: {a: 5} -> means its frozen

// Now use this trick
var tempObj = {};
for(var i in obj){
    tempObj[i] = obj[i];
}
console.log(tempObj); // {a: 5}

// Resetting obj var
obj = tempObj;
console.log(obj);// {a: 5}

obj.b = 10; // trying to add something to obj var
console.log(obj); // output: {a: 5, b: 10} -> means it's not frozen anymore

Note: Keep one thing in mind, don't do tempObj = obj, then it won't work because tempObj is also frozen there.

Fiddle here: http://jsfiddle.net/mpSYu/


There is no way to do this, once an object has been frozen there is no way to unfreeze it.

Source

Freezing an object is the ultimate form of lock-down. Once an object has been frozen it cannot be unfrozen – nor can it be tampered in any manner. This is the best way to make sure that your objects will stay exactly as you left them, indefinitely