top | item 38622218

(no title)

chalsprhebaodu | 2 years ago

Take this from someone who has been down this road: you are way over-thinking this.

Until you accept this, you will be holding yourself back as a JavaScript developer.

If you need objects with encapsulated state and methods, use classes.

OOP does not magically introduce baggage or complexity.

Your proposed solution is still OOP. Coming up with your own OOP framework will introduce baggage and complexity.

Classes are highly optimized in modern JS engines.

Classes can be transpiled to performant code for legacy JS engines.

There are times when classes are not the right choice, but avoiding classes when they’re the obvious right choice is a clear indicator that a developer is unwilling to actually learn JavaScript.

Edit:

Your example code also has a bug, where your methods don’t actually mutate the properties of the returned object.

Please take the leap and just learn to use JavaScript classes!

discuss

order

No comments yet.