Axel Rauschmayer
Oct 22, 2015 · 1 min read

“Single inheritance taxonomies are an anti-pattern.”

Not always, but often. That’s why it’s important that JavaScript gets traits (which were one of the reasons for introducing classes).

“It could be composition all the way down”

Traits give you what you call composition. Very often, classes will be the location where people assemble traits.

“Using class, you’re forced to use `new`, which could break calling code if you need to refactor to a different instantiation method later.”

You are lucky if refactoring from a class instantiated via `new` to a function call is the biggest change in your code (most refactorings are much more tricky). Modern IDEs allow you to completely and safely automate such a refactoring. For my own code, I wouldn’t mind. For libraries, it is indeed something you need to consider. But you do have the option of returning an object from a class constructor (turning it into a factory).

Axel Rauschmayer

Written by

JavaScript: blogger @2ality, trainer @Ecmanauten, organizer @MunichJS Books: ES5: ES6: More: @mediahaystack

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade