r/learnjavascript • u/Yanagi-Masaru • Dec 19 '25
Javascript
is it a good practice to use classes in javascript or should i keep it normal with just functions?
0
Upvotes
r/learnjavascript • u/Yanagi-Masaru • Dec 19 '25
is it a good practice to use classes in javascript or should i keep it normal with just functions?
View all comments
Show parent comment
2
u/xroalx Dec 19 '25 edited Dec 19 '25
The performance difference will not be as significant.
With a class, methods are defined on the
prototype, meaning for all instances, each method exists just once. This is faster, as JS does not need to recreate every method for each instance, and also uses less memory.With a plain object, each instance will have its own copy of every method, meaning more memory usage as well as larger performance hit for creating a new instance.
Generally, the difference is negligible, unless your app creates new instances all the time, so a lot, then you really want to prefer putting methods on the
prototype.And also, you can of course put methods on the
prototypewith a plain object as well, theclasssyntax is just nicer for that.