arrow
的汉语意思是箭头
,function
的汉语意思是函数
。
arrow function
的意思是箭头函数
。
arrow function
是ECMAScript
对Lamda表达式
的实现。
(param1, param2, …, paramN) => { statements }
(param1, param2, …, paramN) => expression
// equivalent to: => { return expression; }
// Parentheses are optional when there's only one parameter name:
(singleParam) => { statements }
singleParam => { statements }
// The parameter list for a function with no parameters should be written with a pair of parentheses.
() => { statements }
function sum(...theArgs) {
return theArgs.reduce((previous, current) => previous + current);
}
console.log(sum(1, 2, 3)); // expected output: 6