Skip to content

Instantly share code, notes, and snippets.

@gjohnson
Created April 20, 2013 11:20
Show Gist options
  • Save gjohnson/5425663 to your computer and use it in GitHub Desktop.
Save gjohnson/5425663 to your computer and use it in GitHub Desktop.
__proto__ behavior
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