Created
May 6, 2011 17:16
-
-
Save mkuklis/959363 to your computer and use it in GitHub Desktop.
prototype, __proto__ & constructor in JS
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 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