Re:ES6 is beautiful
by jbergknoff on Thursday April 07, 2016 @03:03PM
(#11449721)
You're exactly right. Arguably worse than ugly, unnecessary and difficult to parse are that many of these things are difficult to research with a search engine. For example, `const { user, post } = this.props;` there is nothing to plug in to a search engine (and the meaning is not obvious, even to somebody with plenty of experience in ES5). Same thing with `arr1.push(...arr2);`.
[ Parent
| on HN ]
Destructuring assignments are extremely useful, especially within function signatures.
Without knowing the type of what you're destructuring though, that's quick to land you in some type of undefined hell.
Why wouldn't you know what your destructuring?
`({ id, option = true, name = 'unnamed' }) => // ...`
replaces
``` function(userObject) {
const id = userObject.id;
const option = userObject.option || true;
const name = userObject.name || 'unnamed';
// ...
}
```I think this comparison speaks for itself. In pre-es6 code bases you TONS of code that looks like the second.
Come off it, destructuring is hardly unique to javascript.
What syntax would you recommend/prefer for unwrapping 'props'?
This is a real problem for me these days. I see a new syntax in someone else's codebase and it is very difficult to google it.
Take a look at this site http://es6-features.org/ there is even comparison ES6 vs ES5 code. You can just go over every feature really fast a then you may get rough idea where to look next time you feel lost.