高级前端
js
【Q581】箭头函数和普通函数的区别

箭头函数和普通函数的区别

Issue 欢迎在 Gtihub Issue 中回答此问题: Issue 597 (opens in a new tab)

Author 回答者: shfshanyue (opens in a new tab)

箭头函数无 this,无 prototype

Author 回答者: haotie1990 (opens in a new tab)

箭头函数有几个使用注意点。

  • 箭头函数没有自己的this对象。

  • 不可以当作构造函数,也就是说,不可以对箭头函数使用new命令,否则会抛出一个错误。

  • 不可以使用arguments对象,该对象在函数体内不存在。如果要用,可以用 rest 参数代替。

  • 不可以使用yield命令,因此箭头函数不能用作 Generator 函数