/*箭头函数
1、function(){
......
}
简写为()=>{}
2、如果有且仅有一个参数,()也可以不写
如果有且仅有一个语句并且是return,{}也可以不写
function (a){
return a + 2;
}可以简写为
a=> a+2;
3、修正this的指向,this始终指向初始的对象
*/
// let json = {
// a: 12,
// fn: function () {
// console.log(this);//json
// alert(this.a);
// }
// }
//
// json.fn();//12
//
let json = {
a: 12,
fn: ()=>{
console.log(this);//window
alert(this.a);
}
}
json.fn();//undefined,window上没有a
箭头函数
最新推荐文章于 2024-08-12 17:14:51 发布