Thanks but massively? function() {} vs () => {}?
e.g.
ES5
users.map(function(user) {
return user.name
}).filter(function(name) {
return name.length < 30
}).sort(function(a, b) {
return a.length - b.length
})
vsES6
users
.map(user => user.name)
.filter(name => name.length < 30)
.sort((a, b) => a.length - b.length)
Contrived, but typical example. var _this = this;
call(function (){
return _this.value;
});
versus call(() => this.value);
So yeah, much more readable, and less issues with this binding to some other caller or window. function(){}.bind(this)
vs
() => {}
And for a single expression the `{}` are optional and a `return` is implied, which is pretty nice for .map()/.sort(), etc.Automatically bound `this` is super important. It's very easy to forget one `.bind(this)` (or `that` alias) somewhere, especially when you have several levels of callback nesting.