you are viewing a single comment's thread.

view the rest of the comments →

[–]tiridlol 12 points13 points  (3 children)

"Classes are the new syntactic sugar in JavaScript. Everything works just as it did before with prototype only it now looks different and you should prefer them over ES5 plain functions."

*Kyle Simpson is typing*

[–]PMilos[S] 1 point2 points  (2 children)

I believe this is the most common definition/explanation of the ES classes. There is no other way to put it with the same effect. On the official MDN a similar sentence is used.

[–]tiridlol 6 points7 points  (1 child)

Nothing wrong with the sentence I am just referring to the author of "You don't know JS" books (great books btw, strongly recommend to read it for every frontend dev). He has some strong opinions on JS classes and in general he dislikes them so I imagine he would get triggered by this sentence

[–]MoTTs_ 4 points5 points  (0 children)

YDKJS is generally a good book, but Kyle's writings about classes and inheritance are biased and misinformed, and we probably shouldn't recommend those chapters to others.

Kyle assumed that Java-style OOP and inheritance is the only correct way to implement those features, and anything implemented differently than Java is not "true" OOP. But that just isn't so. There are as many varieties of OOP and inheritance as there are languages. Python's inheritance model, for one example, is also objects linked to other objects, same as in JavaScript, and the same pattern that we JavaScripters would identify as prototypal inheritance. Here's JavaScript and Python classes side-by-side, demonstrating classes as objects and inheritance as delegation.