Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

说说箭头函数? #28

Open
habc0807 opened this issue Aug 15, 2020 · 2 comments
Open

说说箭头函数? #28

habc0807 opened this issue Aug 15, 2020 · 2 comments

Comments

@habc0807
Copy link
Owner

habc0807 commented Aug 15, 2020

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

@habc0807
Copy link
Owner Author

habc0807 commented Aug 15, 2020

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

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

@Jack-rainbow
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants