Hacker News new | ask | show | jobs
by hajile 2998 days ago
In my experience, the class syntax has been more bad than good. Devs with experience in other languages simply start writing classical OOP code without realizing the ramifications of what they are doing.

Unless you are creating thousands of rigidly structured instances (never adding/removing properties or changing property types), you are almost always going to be better off using the factory pattern instead where you get other benefits like no `new` and real privacy.

1 comments

> the ramifications of what they are doing

Which are? And why is "no new" a benefit?

IMO it's a good thing that you can write JS in the way you write other languages. It makes it a lot easier for developers to get going with it.

I'm trying to learn modern JavaScript at the moment, as well as getting to grips with prototypes I now have additional class syntax to learn and understand.

I've gone from learning one way of doing things to two, how is that easier to get going with?

Because now there's one way instead of everyone bringing their own createClass/inherits implementation.

Also, prototypical classes like `function User` are now rare in my experience going forward.

> Because now there's one way instead of everyone bringing their own

In theory. In reality there's everyone bringing their own plus one more.

I think the appeal of JS is that it's a universal runtime, not anything about the language itself. I really wish syntactic changes would be left to transpilation.. because that's what every JS developer is doing anyways.