Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I don't understand why everyone considers classes controversial. If you look at code in the wild, it already does what classes desugar to: everyone already writes constructor function and attaches properties to their prototypes.

At least now with classes, users coming from other languages wont be as tempted to make their own completely incompatible object systems.



In es6 it's finally possible to properly subclass internal types, it properly separates Class properties and prototypes, and it allows users to extend arbitrary classes.


While my example isn't an issue in ES6, most of the controversial came from CoffeeScript. Using classes comes with classical inheritance expectations. In CoffeeScript, changing class variables would carry through all instances, and that is unexpected from a classical inheritance point of view. However, it made complete sense in the compiled JS.


Maybe I'm misunderstanding, but isn't that the same as static properties on classes in Java?


It is more the "extends" than "class" that is controversial because it eschews other pattern like mixins.


I think extends mixin(SomeClass, AnotherClass) will work.


Sorry, forgot to add an example library: https://www.npmjs.com/package/es6-class-mixin




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: