Created
April 20, 2013 11:20
-
-
Save gjohnson/5425663 to your computer and use it in GitHub Desktop.
__proto__ behavior
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 = { hello: 'world' }; | |
var b = {}; | |
// has no own property "hello" | |
console.log(b.hello); // undefined | |
// set __proto__ to b, so "hello" will resolve | |
b.__proto__ = a; | |
console.log(b.hello); // hello | |
// remove __proto__ and sever the underlying magic. | |
b.__proto__ = null; | |
console.log(b.hello); // undefined | |
// now we cant set it. | |
b.__proto__ = a; | |
console.log(b.hello); // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment