箭头函数其实就是lambda函数,JavaScript中的匿名函数
// ES5
var selected = allJobs.filter(function (job) {
return job.isSelected();
});
// ES6
var selected = allJobs.filter(job => job.isSelected());
多个参数时,参数外加上括号(或者使用rest 参数,参数默认值,析构参数):
var total = values.reduce((a, b) => a + b, 0);
箭头函数的执行体可以是一个block,返回值需要显式的return:
(a, b) => {
return a+b;
}
箭头函数的this
从外围作用域继承
Arrow functions do not have their own this value. The value of this inside an arrow function is always inherited from the enclosing scope.