Skip to content

Instantly share code, notes, and snippets.

@shaunwallace
Created November 19, 2014 13:51
Show Gist options
  • Save shaunwallace/095d8d385503ef7214df to your computer and use it in GitHub Desktop.
Save shaunwallace/095d8d385503ef7214df to your computer and use it in GitHub Desktop.
Object.isFrozen()
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