DEV Community

Discussion on: Practical Ways to Write Better JavaScript

Collapse
 
ballpointcarrot profile image
Christopher Kruse

I'm with you on most of this, but I've found code that borders on illegible because of overuse of the spread operator. Especially when dealing with React state, doing an Object.assign is sometimes a lot easier to read than many lines of ...nextObj,.

As always, tend towards readability. The computer does not care what your code looks like, but other devs will.

Collapse
 
taillogs profile image
Ryland G • Edited

Don't even get me started on the spread operator visual design. I think the fact that they didn't come up with a specific syntax and used the existing rest style is atrocious. They actually do opposite things, and are somehow controlled with the same literal. This is just off the top of my head. But why not:

function (...foo) { // before
  foo[0];
}

function (_>foo) { // after
  foo[0];
}
expanded = ...foo; // before
expanded = <_foo; // after