Hacker News new | past | comments | ask | show | jobs | submit login

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




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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: