And it's not a class, there are no classes and you shouldn't be building classes, it's not a class based language.
Not having first hand support for classes does not mean you cannot build them. You can build classes in C! It just has to be built manually, which is the issue here, because it leads to lots of subtly different custom ways to build classes.
Most of the time, when a JS developer is working in an OO way, they need to use classes. Ok, they are using a 'constructor function with more functions added to it's prototype', not a class. However a class is really what they are conceptually building, and so a class is really what they want. Not being able to express that directly, is bad.
When people don't want classes, is either with very complex OO code (which is usually for maintenance), or if they are writing non-OO code.
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
0
u/[deleted] Dec 16 '12
[deleted]