Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Yeah, javascript's prototypal inheritance is flexible enough to simulate classical inheritance. I wouldn't call that a wart.

http://www.prototypejs.org/learn/class-inheritance

http://dojotoolkit.org/reference-guide/dojo/declare.html

Plus, I tend to prefer prototypal inheritance to classical inheritance. I do agree that the constructor pattern using the new keyword and the prototype object is a bit odd, but that's not the only way to have objects inherit from other objects in javascript.



I've used both methods of inheritance.

Prototypical inheritance in the IO Language is a beautiful thing.

Not so much in Javascript.

Class based inheritance in Smalltalk and its dynamic mind-children Python and Ruby are similarly elegant and flexible. Not so much in C++ or Java.

The problem isn't with Prototypical inheritance, its with the implementation of it in Javascript.


The wart is that since classical inheritance isn't built into the language, we get:

1) Crummy syntax. 2) Everybody doing it a different way.


I see your point to some extent. I don't think the functions for mimicking classes provided by libraries like Prototype and Dojo have particularly crummy syntax. But since there isn't a standardized way to create classes, implementations are usually a little different.

Still, according to this logic, any language that doesn't support classical inheritance has warts. I'm not sure I agree with that. JavaScript doesn't have classical inheritance built in, but I haven't seen anything to make me think that it's really needed from a programming standpoint. Your point #2 is valid, but could that can be attributed to the programmers who use the language rather than the language itself?




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

Search: