Hacker News new | ask | show | jobs
by pluma 3034 days ago
The comparison of the JS output is not entirely fair considering it's likely trying to generate ES5 compatible JavaScript and thus "emulating" classes rather than using the built-in classes available in ES2015 and later.

The output of Babel (which translates newer language features to older versions like ES5) is actually even more verbose because it adds some runtime error handling:

https://babeljs.io/repl/#?babili=false&browsers=&build=&buil...

JavaScript classes build on prototypes with constructors and use prototypal inheritance under the hood, but they're more than the sum of their parts and can be a useful abstraction.

I'd argue that the article is right that in most cases it's probably cleaner in TypeScript to simply use an interface or type alias instead of a class, but although some people like (for example) Eric Elliott have very strong feelings to the contrary, classes are a useful language feature for certain scenarios and avoiding them at all costs can result in worse code than knowing when to use them.