Skip to content

Instantly share code, notes, and snippets.

@qetr1ck-op
Created September 26, 2015 20:02
Show Gist options
  • Save qetr1ck-op/aadce099bb5b8ddf7a02 to your computer and use it in GitHub Desktop.
Save qetr1ck-op/aadce099bb5b8ddf7a02 to your computer and use it in GitHub Desktop.
function Rabbit(name) {
this.name = name;
}
Rabbit.prototype.sayHi = function() {
console.log( this.name );
}
var rabbit = new Rabbit('Rabbit');
rabbit.sayHi(); // (1) ?
Rabbit.prototype.sayHi(); // (2) ?
Object.getPrototypeOf(rabbit).sayHi(); // (3) ?
rabbit.__proto__.sayHi(); // (4) ?
//(1) 'Rabbit', following the rule of "this - is the object before the point."
//this === rabbit
//(2-4) undefined, this === Rabbit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment