1 个回答
cat
cat
cat
报错

1 和 2 不解释了
箭头函数中的this始终是该箭头函数所在作用域中的this,所以 b 的 this 还是 Animal,this.name 就还是 cat
至于 a() 报错的问题,a() 的 this 指向全局,但是 类声明和类表达式的主体都执行在严格模式下,严格模式下全局 this 是 undefined 而不是 Window 对象,所以 undefined.name 就报错了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题