Skip to content

Instantly share code, notes, and snippets.

@egrueter-dev
Created May 30, 2016 01:47
Show Gist options
  • Save egrueter-dev/45ba3fa134a5f5a614ef397799450888 to your computer and use it in GitHub Desktop.
Save egrueter-dev/45ba3fa134a5f5a614ef397799450888 to your computer and use it in GitHub Desktop.
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