Hacker News new | ask | show | jobs
by andreyf 5585 days ago
In the prototype example [1], could someone explain the point or at least the effect of setting Bar.prototype.constructor = Bar?

1. http://bonsaiden.github.com/JavaScript-Garden/#prototype

1 comments

A couple of lines up you see this:

  Bar.prototype = new Foo();
Then, Bar.prototype.constructor == Foo()

So when you create a new instance of Bar, it's constructor still appears to be Foo even though it really isn't. Setting the prototype.constructor fixes that.