Created
May 30, 2016 01:45
-
-
Save egrueter-dev/963bf2b461b44765c33b9fd1afd249a6 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
// Let's assume we have object o, with its own properties a and b: | |
// {a: 1, b: 2} | |
// o.[[Prototype]] has properties b and c: | |
// {b: 3, c: 4} | |
// Finally, o.[[Prototype]].[[Prototype]] is null. | |
// This is the end of the prototype chain as null, | |
// by definition, null has no [[Prototype]]. | |
// Thus, the full prototype chain looks like: | |
// {a:1, b:2} ---> {b:3, c:4} ---> null | |
console.log(o.a); // 1 | |
// Is there an 'a' own property on o? Yes, and its value is 1. | |
console.log(o.b); // 2 | |
// Is there a 'b' own property on o? Yes, and its value is 2. | |
// The prototype also has a 'b' property, but it's not visited. | |
// This is called "property shadowing" | |
console.log(o.c); // 4 | |
// Is there a 'c' own property on o? No, check its prototype. | |
// Is there a 'c' own property on o.[[Prototype]]? Yes, its value is 4. | |
console.log(o.d); // undefined | |
// Is there a 'd' own property on o? No, check its prototype. | |
// Is there a 'd' own property on o.[[Prototype]]? No, check its prototype. | |
// o.[[Prototype]].[[Prototype]] is null, stop searching, | |
// no property found, return undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment