Created
November 19, 2014 13:51
-
-
Save shaunwallace/095d8d385503ef7214df to your computer and use it in GitHub Desktop.
Object.isFrozen()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var obj13 = Object.create({}); | |
obj13.foo = 'x'; | |
obj13.bar = 'y'; | |
Object.freeze( obj13 ); // freezes the object completely | |
Object.isFrozen( obj13 ); // returns true | |
Object.isFrozen({}); // returns false because a newly created object is extensible by default | |
var frozenObj = Object.preventExtensions({}); | |
Object.isFrozen( frozenObj ); // returns true since we have set it to be non-extensible | |
var obj14 = { x : true }; | |
Object.isFrozen( obj14 ); // returns false because new objects with properties are extensible | |
Object.preventExtensions( obj14 ); // returns false because the object is still configurable and writable | |
delete obj14.x; | |
Object.isFrozen( obj14 ); // returns true as an object with no properties that is not newly created becomes frozen |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment