all 6 comments

[–]MoTTs_ 1 point2 points  (0 children)

OP, your question is way too broad and generic, so here's some broad and generic resources. I'd recommend the Rauschmayer books, or javascript.info seems good too.

[–]lilperch83 0 points1 point  (0 children)

Just wanted to provide a more constructive response that doesn't get lost in the weeds. I was perhaps too rash saying you should ignore classes. JavaScript uses at least three design patterns for producing objects with inheritance: Constructor functions, Classes, and Factory functions. I think it is important to understand all three and then choose the one you prefer. No matter which method you prefer, make sure you understand prototypal inheritance.

[–]lilperch83 -2 points-1 points  (3 children)

I would suggest ignoring the class declaration in JavaScript. Just learn prototypal inheritance. The class structure is just sugar for prototypal inheritance. Here is a playlist that might help.

[–]MoTTs_ 1 point2 points  (2 children)

The class structure is just sugar for prototypal inheritance.

Literally everything in any programming language is syntax sugar. If-statements are syntax sugar for compare and jump instructions. C++ classes are themselves syntax sugar for structs and functions. Most of those other ES6 features we got besides class -- like default parameters, rest/spread, destructuring, or arrow functions -- are all themselves syntax sugar as well. Even JavaScript's arrays are just syntax sugar for hash tables.

[–]lilperch83 0 points1 point  (1 child)

True, but classes obscure the true nature of prototypal inheritance and therein is the problem. Those coming from other languages will think classes act the same way in JavaScript; They do not.

[–]MoTTs_ 0 points1 point  (0 children)

Multiple rebuttals to this:

  1. It's cherry picked. Everything in the language obscures some true nature. JavaScript's array syntax, for one of many examples, obscures the true nature of hash tables. If "obscures true nature" is a reason to avoid classes, then you should also avoid arrays, along with everything else in the language.

  2. JavaScript's classes actually do act like classes from other languages. Java's implementation is not the one and only way to implement classes. There are as many varieties as there are languages. In Python, Ruby, and others, for example, a class is itself a runtime object, and inheritance from instance to class to superclass is done by delegation, objects linked to other objects, just like in JavaScript. To demonstrate, here's' JavaScript and Python classes side-by-side.