Created
February 7, 2016 01:26
-
-
Save josescasanova/e6b95e000d5c57eea46d to your computer and use it in GitHub Desktop.
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 a = "mystring", | |
b = new String( "mystring" ); | |
Object.defineProperty( b, 'foo', { value: 42, enumerable: false }); | |
console.log(b.foo); // 42 | |
Object.defineProperty( a, 'foo', { value: 42, enumerable: false }); | |
// TypeError: Object.defineProperty called on non-object | |
// trying another way: | |
a.foo = 42; | |
// remember, this is equivalent to: | |
// new Number(a).foo = 42; | |
// …so the 'foo' property is defined on the wrapper, not on 'a' | |
console.log(a.foo); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment