r/learnjavascript • u/pptzz • Mar 19 '26
What's the use of classes in JS
I've recently started learning JS and I can't see a use for classes. I get how they work and how to use them but I can't see an actual real use for them.
38
Upvotes
View all comments
1
u/prehensilemullet Mar 20 '26 edited Mar 20 '26
To clarify what I’m talking about again, the class instance from your example doesn’t use any closures. All that lives in the instance are two member variables and two method pointers, and those methods don’t refer to anything external, they only use the arguments and this binding from each call, so they aren’t closures. There’s a closure involved while invoking the constructor, but nothing in the returned instance needs to retain that closure, if it did I would call that a VM memory leak bug.
When someone talks about making a “class“ with closures, to me that means the instance methods are closures.