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

箭头函数相关 #7

Open
Liqiuyue9597 opened this issue Jul 30, 2020 · 2 comments
Open

箭头函数相关 #7

Liqiuyue9597 opened this issue Jul 30, 2020 · 2 comments

Comments

@Liqiuyue9597
Copy link
Owner

Liqiuyue9597 commented Jul 30, 2020

字节:

var x = 1
//说出输出
x => x 
x => {x} 
x => ({x}) 
x => {{x}}

百度:

  • 讲一下箭头函数的this
  • 箭头函数可以写成构造函数吗?
  • 箭头函数有原型吗/可以实现原型链吗?
@Liqiuyue9597
Copy link
Owner Author

Liqiuyue9597 commented Aug 14, 2020

作业帮: function与箭头函数的区别
这个区别其实就是百度问的那几个问题。

答案:

  1. 不能像function一样显示命名,只能赋值给其他变量隐式命名
  2. 箭头函数不能用做构造函数,也没有prototype属性,所以也不能使用new 关键字
  3. 箭头函数不会创建新的作用域,会绑定到所在的词法作用域中,因此不会改变this指向。(this、arguments和super都属于所在的父作用域)

@liboliang01
Copy link

箭头函数的函数体的return可以省略,使用小括号包裹返回值

// 以下几种写法含义相同
x=>x
x=>(x)
x=>{
  return x
}

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