箭头函数
箭头函数和原来相比,只是写法上的改进:
1、如果只有一个参数,()可以省
2、如果只有一个 return,{ } 可以省
function show(){
}
let show = () =>{
}
实例1、省略( ) 和 { }
let show = function(a){
return 2*a
}
let show = a => 2 * a //如果只有一个参数,()可以省,如果只有一个 return,{} 可以省
实例2、省略 { }
let arr = [32, 58, 46, 98, 89, 77]
arr.sort(function (n1, n2) {
return n1 - n2
})
arr.sort((n1, n2) => n1 - n2) //只有一个 return 可以省略 {}