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 o = { | |
foo: "bar" | |
}; | |
// adding a new property normally: | |
o.hey = "guys"; | |
// preventing further extensions: | |
Object.preventExtensions(o); | |
// silent error, or TypeError under strict mode: | |
o.anotherProp = "This will fail!"; | |
// existing properties can still be changed: | |
o.hey = "gals"; | |
var o = { | |
foo: "bar" | |
}; | |
// adding a new property normally: | |
o.hey = "guys"; | |
// deleting a property normally: | |
delete o.hey; | |
// sealing the object: | |
Object.seal(o); | |
// silent failure, or TypeError under strict mode: | |
o.anotherProp = "This will fail!"; | |
// existing properties can still be changed if they were writable: | |
o.foo = "baz"; | |
// silent failure, or TypeError under strict mode: | |
delete o.foo; | |
//We can do everything Object.seal does, but also protect data properties | |
//from being overwritten by using the Object.freeze method. | |
var o = { | |
foo: "bar" | |
}; | |
// adding a new property normally: | |
o.hey = "guys"; | |
// deleting a property normally: | |
delete o.hey; | |
// sealing the object: | |
Object.freeze(o); | |
// silent failures, or TypeErrors under strict mode: | |
o.anotherProp = "This will fail!"; | |
o.foo = "baz"; | |
delete o.foo; | |
var o = { foo: "bar" }; | |
Object.preventExtensions(o); | |
Object.defineProperty(o, "foo", { | |
writable: false, | |
configurable: false | |
}); | |
// Object.isFrozen(o) === true | |
//http://www.jimmycuadra.com/posts/ecmascript-5-tamper-proofing-objects |
No comments:
Post a Comment