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

I don't think that's the issue, though I did come to JS from a python background, so that that for what it's worth.

For me the problem is that people tend to use prototypal inheritance to implement class inheritance patterns, but there are so many ways to do that, so whenever you read code, it takes a while to figure out what people are doing.

If there was a large gain to prototypal inheritance, I might be willing to accept it, but I havent' seen (does anyone have examples?) of really cool/useful things you can do with prototypes that you cannot do with class based inheritance? Because the increased flexibility leads to confusion without added benefit, I don't see the point.

Contrast that with dynamic typing, where I think there are huge benefits which offset the added cost.

also - from reading that article, it seems that JS's prototypal system has a large number of gotchas, and thats bad regardless of what kind of inheritance system your language implements.



I don't have examples of prototype inheritance being better than classical inheritance because there is no classical inheritance in JavaScript. In JS, prototypal inheritance is the de facto way to do inheritance. Whether you like it or not.

Now what is the most productive/sane path?

1. work against the language to have something that looks like classical inheritance.

2. work with the language and learn prototypal inheritance


What I mean is that projects like coffeescript, and spine.js build classical inheritance patterns on top of JS and they work rather well.

I'm looking for someone to contrast either a classical inheritance system built on top of JS prototypes vs using JS prototypes in another way, OR just show me something cool you can do in JS prototypes, that you can't do with python or ruby classes. Contrasting js prototypes with classes in another language is fine for this exercise, I'm trying to understand conceptually why prototypal inheritance is good. Otherwise, I don't see how prototypal inheritance adds value over python/ruby inheritance schemes.

I also believe it's completely feasible and logical to critique language features, and still use them at the same time out of necessity. I still use prototypal inheritance, just through coffeescript classes


There are many small and big projects providing approximations of a class system in JS. All of them use prototypal inheritance under the hood.

They work well because, for most of us, both systems are designed and used for the same thing: creating base objects, instanciating objects based on those base objects and creating other base objects based on previous base objects.

All of the pseudo-classical systems devised by library authors are used exactly the same way as we have used prototypal inheritance for years before JavaScript became fashionable again. Both systems do exactly the same thing and using one over the other is just a matter of taste or habit.

I see a lot of people claiming that the classical system is superior to the prototypal system and that JavaScript sucks because it is designed around the wrong system. AFAIK, nobody is claiming the opposite. Prototypal inheritance has been there since the beginning, some people learn it without complaining, some others write long rants because they don't want to adapt to another paradigm. Guess which ones are the most reasonable?

Prototypal inheritance doesn't add value over other inheritance systems. It's just the default system at the heart of JavaScript. Whether it's better or worse doesn't matter as there's no alternative. Comparing JavaScript's prototypal inheritance to Java/PHP/Ruby/Python/C++/C#'s own systems makes no sense because we are not in a position to choose. We can't use any of these languages to dynamize your HTML in a browser, do we?

The day a vendor decides to expose the DOM to Python || Ruby will be an interesting day, for sure. But for now…

… if you don't like prototypal inheritance use one of those classical libs if it makes you feel better because, in reality, it makes no difference: you'll still use prototypal inheritance anyway.

But, to answer your question, I like the fact that I can add Car.prototype.honk on the fly, anywhere in my script, and be certain that all of the objects inheriting from Car (SportsCar, DeliveryCar, CheapCar…) will be able to honk(). I know this is available in Ruby, I don't think it's doable in PHP and I don't know for the other languages.




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

Search: