Skip to content

Instantly share code, notes, and snippets.

@incompl
Created October 20, 2011 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incompl/1300292 to your computer and use it in GitHub Desktop.
Save incompl/1300292 to your computer and use it in GitHub Desktop.
Shows that .__proto__ is not the same as .constructor.prototype
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