YDKJS 'This & Objects' — Why would I care about classes?

In the book they dedicate whole section to classes. However, YDKJS constantly keeps reminding us that classes mechanism prior to ES6 does not really exist and that trying to recreate it is a waste of time.
My question is — why bother with it then? Why do programmers use it, if it is just a waste of time?

Because most of the object oriented languages operate on classes. Frankly, it seems that prototypes and lack of classes are the biggest source of confusion for developers who had used other languages before, and then came to JS. Author does not know your background, so he dedicated an entire section for those with some programming experience. That plus the fact, that you can find an awful lot of JS resources that actually show you how to “use classes” :wink:

For me that part of the book was really hard one, I understood it better after learning a little bit of python :wink:

Prototypal inheritance is cool, but how it is implemented in JavaScript is just horrible. Every function is practically a ‘class’ and has prototype prop by default, every object has hidden proto property, creating subclasses is a mess, ‘classes’ won’t error if they are invoked without new keyword which can be disastrous, etc, etc…

ES6 classes are ‘reimplementation’ of prototypal inheritance. Underneath everything stays the same, but programming interface a lot better.

1 Like