Skip to content

Instantly share code, notes, and snippets.

@josescasanova
Created February 7, 2016 01:26
Show Gist options
  • Save josescasanova/e6b95e000d5c57eea46d to your computer and use it in GitHub Desktop.
Save josescasanova/e6b95e000d5c57eea46d to your computer and use it in GitHub Desktop.
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