没有自己的this
- 箭头函数中的this实际是外层函数的this
const test={pro:'pro',con:()=>console.log(this)}
test.con() //window
const foo={bar:{con:test1.con},pro:'foopro'}
foo.bar.con() //window(this与调用层数没有关系this是函数才有的内部变量,所以箭头函数的this总是来自外层函数中的this,这里指向window)
foo2 = {bar:{con:function(){console.log('function',this)}},pro:'foopro'}
foo2.bar.con() //function {con: ƒ} (指向函数的调用者bar)
- 箭头函数不能当作构造函数使用
- 不能用call()、apply()、bind()这些方法去改变this的指向
不存在arguments对象
该对象在函数体内不存在。如果要用,可以用 rest 参数代替。
rest形式为(…变量名)可以获取函数的多余参数,并且获取到的是真正的数组对象
arguments只是一个类数组对象,除了length属性和可以使用arguments[0]获取元素之外没有数组的其他特性,可以使用[…arguments]或者Array.prototype.slice.call(arguments,0)、Array.prototype.concat.call(arguments,0)转为数组
没有prototype属性
var foo = () => {
return 1
}
function bar(){
return 2;
}
console.log(foo.prototype) //undefined
console.log(bar.prototype) // {constructor:f}
不可以使用yield命令
因此箭头函数不能用作 Generator 函数。
这个还不知道为什么