-
-
Save luongs3/628b3a1ff1049158e85a9760481501ba to your computer and use it in GitHub Desktop.
This file contains 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
// Without Strict Mode | |
NaN = "lol"; // Nothing happen | |
var obj = {}; | |
Object.defineProperty(obj, 'prop', {value: 1, writable:false}); | |
obj.prop; // => 2 | |
obj.prop = 10; | |
obj.prop; // => 2 | |
// With Strict Mode | |
"use strict"; | |
NaN = "wtf"; // TypeError | |
var obj = {}; | |
Object.defineProperty(obj, 'prop', {value: 1, writable:false}); | |
obj.prop; // => 2 | |
obj.prop = 10; // Uncaught TypeError: Cannot assign to read only property 'prop' of object #<Object> | |
// Assignment to a getter-only property | |
var obj = { get x() { return 1; } }; | |
obj.x = 2; // Uncaught TypeError: Cannot set property x of #<Object> which has only a getter | |
// Assignment to a new property on a non-extensible object | |
var fixedObj = {}; | |
Object.preventExtensions(fixedObj); | |
fixedObj.newProp = "new value"; // Uncaught TypeError: Can't add property newProp, object is not extensible |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment