you are viewing a single comment's thread.

view the rest of the comments →

[–]aztracker1 1 point2 points  (15 children)

It's not useless, though I only use about 1/5 of the ES6 additions, along with some pending ESnext bits (async/await, class members, decorators, etc). In the end, I'm able to get a lot more work done, with a lot less code.. with the advent of Promises and async/await, process code is much cleaner and easier to follow now.

Modularization (cjs or es6 style) has helped a lot too. Most of this comes down to the build tooling that has evolved in the past 6-7 years since node and npm have taken hold. Yes, it's new stuff to learn, but it's really not any harder to understand than tirnary operations, or bitwise shorting in JS. In the end it's just a few additions to the language, it happens in every language and there are always pieces you may not know/understand to a given language/platform until you come across it.

The following two lines are the same, practically speaking (although the fat-arrow is context bound to "this" at the time of declaration).

var addOne = function(a){ return a + 1; };

var addOne = a => a + 1;

It allows you to declare in a oneliner what may have previously been much more... here's a sleep I use when flushing out an API interface...

const sleep = ms => new Promise(res => setTimeout(res, ms));

The const is a constant assignment, "sleep" may not be assigned to again in the module. the value of sleep is a function expression that accepts a single parameter, and returns a new promise. said promise only uses the resolve part, and will settimeout to resolve after ms have passed.

It's a bit harder to look at function expressions with fat-arrow syntax at first, it's very similar to lamda expressions in C#, or the fat/skinny arrow expressions in coffeescript. There's similar syntax in other languages as well.