fe-interview icon indicating copy to clipboard operation
fe-interview copied to clipboard

说说箭头函数?

Open habc0807 opened this issue 4 years ago • 2 comments

可以从箭头函数的定义、参数、函数体、以及跟普通函数的使用上区别聊聊。

habc0807 avatar Aug 15 '20 03:08 habc0807

  • 箭头函数没有 prototype,所以箭头函数不能当构造函数使用;
  • 箭头函数不会创建自己的 this,它的this指向外层离它最近的 this,及时通过call、apply、bind也不能改变this的指向;
  • 箭头函数不绑定 arguments,可以使用 rest 来访问箭头函数的参数列表

以上箭头函数跟普通函数的不同,根源是箭头函数没有的this和原型属性。

habc0807 avatar Aug 15 '20 08:08 habc0807

  • 1.箭头函数的this指向外边一层函数的this,且不可以通过 call, bind,apply改变this指向
  • 2.箭头函数没有arguments
  • 3.箭头函数不可以new,因为不可以改变this指向和没有prototype

Jack-rainbow avatar Sep 22 '20 07:09 Jack-rainbow