25
๐ฅ Discussion ๐ฅ ES6 Classes. Good or Evil?
(programming.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
The
class
keyword exists for a reason and it has a perfectly fine use case when you need to make use of creating new objects. I think it may be disliked because people come over from Java assuming you need to define everything as objects/classes when we have modules and other methods of doing the same thing with a little bit less clutter. I recommend reading up on the underlying functionality and how classes and objects work compared to modules.It's disliked because it uses a "class" keyword but it isn't a class. JavaScript has prototypes, not classes.
I somehow feel like there's an allergy of sort towards classes in general in JavaScript/TypeScript. Many projects I've worked on gravitate towards more functional/plain-old-objects sort of paradigm and it feels like classes are avoided just because they don't feel like idiomatic JS.
Yes. This seems to be one of the common arguments against "classes": they're not exactly classes in the traditional sense, and everything you can do in JavaScript can be done so without touching the
class
keyword. It's basically syntactic sugar that adds more confusion to the language, or so I heard. I've read this article that explains the flaws behind with this feature: https://www.toptal.com/javascript/es6-class-chaos-keeps-js-developer-up