Prototypes are simply more complicated than classes. They change behavior of objects, whereas classes _define_ behavior of objects. The syntax doesn't help it either.
Prototypes are simply more complicated than classes. They change behavior of objects, whereas classes _define_ behavior of objects. The syntax doesn't help it either.
No, that's an objective statement, on which the creator of the language and some of the greater gurus of it, agree.
>My opinion is that prototypes are simpler than classes.
Not in the way prototypes are implemented in JS.
The creator of the language was apologized lots of times for it's many warts (due to lack of design and time constraints plus limited initial scope for the language), and the greatest of its' gurus had to write a book called "Javascript, THE GOOD PARTS".
Someone who cannot see the flows of Javascript's implementation of prototype inheritance, seriously cannot assess good and bad software design.
Secondly, you appear to be claiming that Crockford offers strong criticism of JS's inheritance model in The Good Parts. If that's what you took away from it, I think you would do well to reread that chapter.
Of course JS's inheritance system is imperfect just like that of pretty much any other language.
Well, he sure is on a very short list of js programmers. Who other can you add? Maybe Resig? Ashkenas?
>Secondly, you appear to be claiming that Crockford offers strong criticism of JS's inheritance model in The Good Parts. If that's what you took away from it, I think you would do well to reread that chapter.
No, I'm saying that Crockford doesn't like the way prototypal inheritance is implemented/exposed in javascript --not that prototypal inheritance is inherently bad. He even writes that the basic action of getting prototypal inheritance is not first-class in js:
"In a prototypal system, objects inherit from objects. JavaScript, however, lacks an operator that performs that operation."
And in order to use prototypal inheritance he has written a wrapper function to hide all the inheritance boilerplace correctly. (As has every other js programmer I know of, using several patterns).
[citation needed]
I'd argue the opposite: "Prototypes are simply more _intuitive_ than classes."
OO-design says that X is-a Y is-a Z, with inheritance providing the main form of structure.
Prototypical-design says that X is-like-a Y, but with these differences. This NPC (specific, X) is like any other NPC (general, perhaps the original NPC prototype), but with the name Fred and this custom AI code.
They're different ways of thinking, but prototypes are certainly not more complicated than classes in the general case.
----
As for the syntax, though, I totally agree with you.
Only if you try to make them act like classes.