Why I no longer write classes in #Javascript: I don't need them
Why I no longer write classes in #Javascript:
I don't need them.
Instead, I use:
1. Plain objects (data only, no behavior)
2. Pure functions (no side-effects, no outside dependencies)
Easy to test. ✅
Easy to understand. 🧠
Easy to compose. 🏘
Why I avoid #javascript classes:
1. Confusing `this` keyword behavior (admittedly arrow functions reduced this pain)
2. Needless extra syntax
3. JavaScript classes are a misleading abstraction over prototypes
4. Pure functions are easier to test, understand, and compose
Many asked, so here's a simple example.
I'm solving the same problem using a class vs pure functions: https://codesandbox.io/s/amazing-kapitsa-fpu4o?file=/src/index.js