Created
October 20, 2011 02:46
-
-
Save incompl/1300292 to your computer and use it in GitHub Desktop.
Shows that .__proto__ is not the same as .constructor.prototype
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
function Parent() {} | |
var parent = new Parent(); | |
function Child() {} | |
Child.prototype = parent; | |
var child = new Child(); | |
// child inherits directly from parent. this makes sense. | |
console.log(child.__proto__ === parent); // true | |
console.log(child.__proto__ === Parent.prototype); // false | |
// you might think child's constructor would be Child, but it's Parent. | |
console.log(child.constructor === Parent); // true | |
// as a result, you get this | |
console.log(child.constructor.prototype === parent); // false | |
console.log(child.constructor.prototype === Parent.prototype); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment