1

preventExtensions() method prevents extensible object from extending, isn't there way to redo it? Or isn't there a method or trick to convert non-extensible object to extensible object. I wanted to know whether it is possible or not.

Sunil D.
  • 17,983
  • 6
  • 53
  • 65
Maizere Pathak.Nepal
  • 2,383
  • 3
  • 27
  • 41
  • You could probably create a copy of the object, and modify it. See http://stackoverflow.com/q/122102/218196. – Felix Kling Apr 28 '13 at 17:29
  • 1
    Set the old object as the prototype of a new object that you create. That'll let you maintain the integrity of the old one while inheriting from it. `var new_obj = Object.create(non_ext_obj);` –  Apr 28 '13 at 17:57

1 Answers1

1

No. You can still modify the prototype, but not the object itself.

From MDN @ https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/preventExtensions:

If there is a way to turn an extensible object to a non-extensible one, there is no way to do the opposite in ECMAScript 5

imsky
  • 3,239
  • 17
  • 16