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