Hacker News new | past | comments | ask | show | jobs | submit login

Some of the code examples given here are perfect examples of what I hate about javascript.

assign(new Dispatcher(), {methodName: function() {}})

Why can't I just define a regular class? Even worse, in the following code snippet the arguments seem mismatched with the previous one:

assign({}, EventEmitter.prototype, {methodName: function() {}})

I can accept this sort of thing if the payoff is high, like getting access to the performance and simplicity of virtual DOM operations in React, but these examples just seem to be to create basic objects.

Maybe object-assign is one of the javascript best practices that keep changing every 2 months and I'm just not paying attention enough? ES6 can't come soon enough.




You can just define a class[1], but you'll need to transpile from ES6.

[1] https://github.com/goatslacker/alt/blob/master/examples/chat...


I think assign should be replaced by having a native class in ES6. I've thought of it like

assign(some newly allocated object, base class [, base class...], object with methods).

It seems to get around the funny stuff with new, prototypes and references.


Feels like yesterday I was told Object.create was the new best way to do this.


The class in ES6 is just syntactic sugar over Object.create. Class is only coming out becuase most people wont learn that javascript has prototypal inheritance, and how to use it. Its a different mental model, in my opinion prototypal inheritance is more expressive and light weight than typical classes from other languages




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

Search: