DEV Community

Discussion on: Stop Using JavaScript Classes!

Collapse
 
raslanove profile image
raslanove • Edited

Ummm. I don't see why you are trying to avoid classes, they are useful and as you mentioned, soon they will be getting more powerful. And you haven't replaced classes with modules, you replaced them with closures. And after removing the comments and blank lines, both implementations of your book class/closure took the same number of lines.

Seriously, your point flew over my head. You are replacing classes with something less flexible, with no gains at all. Modules are nice, and they can be used to wrap classes just like they wrap closures. So, the module point is out of the window.

And about being "more behaviorally consistent", "more pleasant to maintain", "less cumbersome to write", and "easier to read". Really? In what way? Shouldn't you have explained these before concluding them?

Instead of telling people not to use classes, this would have been a nice article about closures and how they can be used for those who have class-phobia.

Collapse
 
greggcbs profile image
GreggHume • Edited

I use functions over classes and I like it. I dont see the need to write a class in nodejs for my use cases.

To use a method in a class you need to import the entire class in the file you are wanting to use the method... modules allow you to pick and import specific functionality.

I like the fact that classes scope functions product.get() or product.create() - but I use good naming conventions on my functions productGetAll() and productCreate() and my IDE loves that because when i start typing 'prod' it gives me a list of all available methods for products - and this works for my db queries, router, utils etc.

For me its about developer experience and patterns to make coding in my projects easy. I just dont see how classes would benefit me with the code i write - but that doesnt mean i avoid them, i just use what I feel is best for my projects.

Collapse
 
jaraujo6 profile image
Johnny Araujo

Thanks for reading! To be honest I care less about how people code and more that they understand the language that they are coding in. I tried to bring that point home in the end so sorry if that didn't come across. I'll do better next time ;)