function(a,b){
…
return a+b
}
等价于 (a,b) => {
…
return a+b
}
() => { … }
如果只有一个参数,括号可以省
如果只有一个return,花括号可以省
//Examplelet arr = [2,11,34,85,23,32]//把数组排序let result = arr.sort(function(x,y){return x - y})console.log(result) // [2, 11, 23, 32, 34, 85]//用箭头函数写let result = arr.sort((x,y) => {return x - y})//因为只有一个 return ,以上可以简写为let result = arr.sort((x,y)=> x - y)//是不是很爽
