Created
May 30, 2016 01:47
-
-
Save egrueter-dev/45ba3fa134a5f5a614ef397799450888 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 o = { | |
a: 2, | |
m: function(b){ | |
return this.a + 1; | |
} | |
}; | |
console.log(o.m()); // 3 | |
// When calling o.m in this case, 'this' refers to o | |
var p = Object.create(o); | |
// p is an object that inherits from o | |
p.a = 12; // creates an own property 'a' on p | |
console.log(p.m()); // 13 | |
// when p.m is called, 'this' refers to p. | |
// So when p inherits the function m of o, | |
// 'this.a' means p.a, the own property 'a' of p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment