A curated list of resources on why ES6 (aka ES2015) classes are NOT awesome
Reverse-inspired by all of the awesome lists on GitHub, like Awesome, Awesome Awesomeness, Awesome JavaScript, Awesome React, Awesome Go, Awesome Elm, etc.
While ES6 brings several useful and syntactically pleasing new features to JavaScript, there are many people in the JS community who feel that adding class syntax to the language was a mistake. I share this sentiment, but I have encountered quite a few programmers in the wild who don't agree or simply don't seem to understand why some of us have this opinion. So, I wanted to create an online reference where people could come to learn specifically about this issue and why they might not actually need class syntax in JavaScript.
- JavaScript is a class-free, object-oriented, & functional programming language. It eschews classical inheritance in favor of prototypal inheritance.
- Many believe prototypal inheritance to be more flexible and freeing than classical inheritance due to its less rigid nature.
- The ES6 class syntax, constructors, the
new
keyword, etc. are ideas taken from the classical inheritance model to make programmers coming from languages like C++, Java, C#, etc. more comfortable and do not really belong in JavaScript. - While prototypal inheritance is very powerful in its own right, there is a growing movement among developers, both within and outside of the JS community (Ex: Composition in Golang), to shift away from inheritance in favor of object composition.
- ES6 class syntax is essentially syntactic sugar that will end up obfuscating the true nature of JavaScript and confusing the next generation of programmers learning it.
- Instead of ES6 classes, you should consider factory functions, object composition, and/or prototypal inheritance via the use of prototypes, object literals, Object.create(), Object.assign(), etc. while avoiding constructors and the
new
keyword altogether.
“If a feature is sometimes dangerous, and there is a better option, then always use the better option.”
--Douglas Crockford
- Common Misconceptions About Inheritance in JavaScript
- Composition over Inheritance
- Delegation vs Inheritance in JavaScript
- Factory functions in JavaScript
- How to Fix the ES6
class
keyword - Introducing the Stamp Specification -- Move Over,
class
: Composable Factory Functions Are Here - Javascript OO Without Constructors
- The Two Pillars of JavaScript -- Part 1: How to Escape the 7th Circle of Hell
- Think twice about ES6 classes
- Ashley Williams: If you wish to learn ES6/2015 from scratch, you must first invent the universe
- Composition over inheritance
- Douglas Crockford: The Better Parts - JSConfUY 2014
- Factory Functions in JavaScript
- Fluent 2013 - Eric Elliott, "Classical Inheritance is Obsolete: How to Think in Prototypal OO"
- Nordic.js 2014 • Douglas Crockford - The Better Parts
- Source Decoded 3: Javascript -- Prototypes, Prototypal Inheritance done right.
Please, ensure your pull request adheres to the following guidelines:
- Search previous suggestions before making a new one, as yours may be a duplicate.
- Make an individual pull request for each suggestion.
- Titles should be capitalized.
- Use the following format:
[Content Title](content link)
- Choose corresponding section (Reading, Videos, etc.) for your suggestion.
- New categories or improvements to the existing categorization are welcome. I would like to add a Tutorials/Examples section at some point. Feel free to get started on that if you have the time.
- The pull request and commit should have clear and useful titles.
- Each section's list, after your addition, should be sorted alphabetically.
This work is licensed under a Creative Commons Attribution 4.0 International License.