Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Created May 6, 2011 17:16
Show Gist options
  • Save mkuklis/959363 to your computer and use it in GitHub Desktop.
Save mkuklis/959363 to your computer and use it in GitHub Desktop.
prototype, __proto__ & constructor in JS
var Foo1 = function() {};
var Foo2 = function() {};
var foo1 = new Foo1();
console.log(foo1.constructor == Foo1.prototype.constructor) // true
console.log(Foo1.prototype.constructor == Foo1) // true
console.log(foo1.constructor == Foo1) // true
console.log(foo1.constructor == foo1.__proto__.constructor) // true
console.log(foo1.__proto__.constructor == Foo1) // true
Foo1.prototype = new Foo2();
console.log('');
console.log(foo1.constructor == Foo1.prototype.constructor) // false
console.log(Foo1.prototype.constructor == Foo1) // false
console.log(foo1.constructor == Foo1) // true
console.log(foo1.constructor == foo1.__proto__.constructor) // true
console.log(foo1.__proto__.constructor == Foo1) // true
console.log('');
var foo3 = new Foo1();
console.log(foo3.__proto__.constructor == foo1.__proto__.constructor) // false
console.log(foo3.__proto__.constructor == Foo2) // true
console.log(foo3.__proto__ == Foo1.prototype); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment