箭头函数的this看定义他的时候,他的外层有没有函数

有:外层函数的this就是箭头函数的this

无:箭头函数的this就是window

obj = {age:18, getAge: ()=>console.log(this.age)}
obj.getAge()
//undefined    定义的时候外层没有函数,指向window

obj = {age:18, getAge: function(){print = ()=>console.log(this.age); print()}}
obj.getAge()
//18    定义的时候外层函数的this就是箭头函数的this

  

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2021-07-03
  • 2022-12-23
  • 2022-02-08
  • 2021-09-01
  • 2021-11-21
  • 2022-01-09
猜你喜欢
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-08-20
  • 2021-12-24
  • 2022-12-23
  • 2021-07-31
相关资源
相似解决方案