And to define how those objects will work, most of the time you just want a class.
With JS prototypes, the syntax is far too verbose. You can build your own code to handle that, but that relates to my earlier point, that you end up with lots of subtly different versions. It's bad for maintenance when that's not standardised.
The other problem is that again, to describe the object, people just want to build a class. The extra abilities that prototypes bring, just complicate matters more than they help.
For example having an objects prototype change, or the functions assigned to that prototype change, or having new functions set to an object to replace that come from the prototype; they all make code much more difficult to reason about.
When you get into using multiple prototypes together, composure and inheritance tend to be better alternatives, because they better describe what you are trying to achieve.
To sum it up, if people are just using constructors/prototypes in class-like ways, why not just give them classes? The fact that they are also less powerful than prototypes, is also what makes them easier to reason about.
Don't be condescending - laziness is one of the three great virtues of a programmer</Larry>.
Also, Javascript's object system pretty much sucks, and if you don't agree with me, you are ugly and stupid</Linus>:
It may be prototypal internally, but the language effectively provides a rather cumbersome class-based overlay through the constructor-function-with-prototype-property mechanism.
A 'real' prototypal language normally provides a clone() method, which Javascript lacked until ES5 arrived. True, it could be added in a few lines of code, but the fact remains that it wasn't provided as a language built-in and virtually no one used this style.
Javascript plain and simple doesn't provide a good mechanism for object extension and code reuse, and that's pretty objectively a deficiency
1
u/[deleted] Dec 16 '12
And to define how those objects will work, most of the time you just want a class.
With JS prototypes, the syntax is far too verbose. You can build your own code to handle that, but that relates to my earlier point, that you end up with lots of subtly different versions. It's bad for maintenance when that's not standardised.
The other problem is that again, to describe the object, people just want to build a class. The extra abilities that prototypes bring, just complicate matters more than they help.
For example having an objects prototype change, or the functions assigned to that prototype change, or having new functions set to an object to replace that come from the prototype; they all make code much more difficult to reason about.
When you get into using multiple prototypes together, composure and inheritance tend to be better alternatives, because they better describe what you are trying to achieve.
To sum it up, if people are just using constructors/prototypes in class-like ways, why not just give them classes? The fact that they are also less powerful than prototypes, is also what makes them easier to reason about.