es6的箭头函数和es5的function函数区别
一.es6的箭头函数
es6箭头函数内部没有this,使用时会上朔寻找最近的this
不可以做构造函数,不能使用new命令,因为没有this
函数体内没有arguments,可以使用rest参数代替
不能用yield,不能使用generator函数
二.疑问
下面代码中的箭头函数arrows的this指向window
let obj = {
aaa: '123',
arrows : () => {
console.log('arrows',this);
},
func : function () {
console.log('func',this);
}
}
obj.arrows(); // window
obj.func(); // obj
————————————————
版权声明:本文为CSDN博主「guxiansheng1991」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/guxiansheng1991/article/details/80009144
浙公网安备 33010602011771号