How to use es6 classes a lot and sleep soundly like you should. (paper for confused newcomers to the brave new world) idchlife Follow Oct 19, 2015 · 4 min read

tl;dr: if you’re not fooling around with .prototype, libraries for mixins etc — using classes is the best option for you to get your code beautiful and readable and extendable. Especially with modules.

Yes, we all love JavaScript, we embrace it’s features and many other things, but I think, there is unhealthy tendency is going on — fighting for using classes or for throwing them in bin for good. I mean, you write some backbone thing and then go to blogosphere one time and there like:

The thing is — it’s always up to you. Whether you use classes, or not. It is true. Do not become result of holy wars about classes and “true pototypal nature of javascript”.

If you use classes — use them without thinking about what’s under the hood with all js constructors and prototypes. Throw away thoughts about all this stuff when using simply classes and classical inheritance.

If you write class, you don’t then change it’s prototype. If you write super, you don’t then write SomeOtherClass.method.call(this). I mean, come on, you’re trying to get some stuff done or fool around?

Use them, like you are using classes in Java/PHP/Ruby/Python. I mean, simply use constructor as constructor, super as super(parent call), extends as extends. The big truth is — es6 has classical inheritance, if you will use it like one, but not like some obscured piece of garbage for programmers from other languages to get used to JS easily.

(this one is for total newcomers) Witness your own pitfalls, when single inheritance is not enough or you don’t understand how to prevent breaking your inner class logic by using “trying to be private with underscore properties/methods”. Then you will find for yourself, what is better and how can pattern/lack-of-pattern save you.

Don’t be the person, who is trying to achieve things through learning JS design patterns (many different modules, classes, singletons etc patterns), keeping in mind something about prototypes, if you’re not fully familiar and experienced with this topic. It will hurt you and your code a lot.

If you are not ready or do not understand thing about prototypes in js — don’t try to use them or patterns around them like it’s the one true way. Use classes — they are simpler, cleaner and there is mostly nothing to discuss and argue about, when building simple systems and projects and not constructing huge libraries/projects like in facebook or twitter or netflix or somewhere else. (yes, yes, even in big projects classes are wonderful solution, but there is huge probability that you are already using composition with them etc. like in any other languages with classical inheritance, but such things are out of this topic)

Es6 classes gives you one clear choice when talking about OOP in js, if you are not familiar and do not want to become familiar with prototypes (there is nothing to be ashamed about, we all just want things to be done, and classes are objectively good choice in comparison with those monstrous creations full of strange modules and ‘classes’ in closures). No more _.extend, no more Backbone.Model.extend, no more React.createClass. Use just: class, extends, super, etc.