箭头功能的词法范围

时间:2019-07-17 05:08:37

标签: javascript

const Car = {
  brand : "Honda",
  Speed : () => {
    console.log("Speed of " +this.brand + " is 120km/hr")
  }
}
Car.Speed();

此代码的输出是:

Speed of undefined is 120Km/hr

我们知道箭头函数是按词法作用域的,那么为什么this.brand返回未定义。

0 个答案:

没有答案