Skip to content

Instantly share code, notes, and snippets.

@matjaz
Created December 6, 2012 10:23
Show Gist options
  • Save matjaz/4223508 to your computer and use it in GitHub Desktop.
Save matjaz/4223508 to your computer and use it in GitHub Desktop.
What does "this.hello = this.hello;" do?
function O1() {
}
function O2() {
// what does this line do?
this.hello = this.hello;
}
O1.prototype.hello = O2.prototype.hello = function() {
console.log('hello');
};
var o1 = new O1(),
o2 = new O2();
o1.hello(); // hello
o2.hello(); // hello
// so what does it do?
console.log(o1.hasOwnProperty('hello')); // false
console.log(o2.hasOwnProperty('hello')); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment