JS 代码的输出结果正确的是__?

const shape = {
  radius: 10,
  diameter() {
    return this.radius * 2;
  },
  perimeter: () => 2 * Math.PI * this.radius
};

shape.diameter();
shape.perimeter();
892 次浏览
  • A、20 and 62.83185307179586
  • B、20 and NaN
  • C、20 and 63
  • D、NaN and 63
请注意, diameter 是普通函数,⽽ perimeter 是箭头函数。 对于箭头函数, this 关键字指向是它所在上下⽂(定义时的位置)的环境,与普通函数不 同! 这意味着当我们调⽤ perimeter 时,它不是指向 shape 对象,⽽是指其定义时的环境 (window)。没有值 radius 属性,返回 undefined 。
挑战成功
1年前
挑战失败
1年前
挑战成功
4年前
挑战失败
4年前

微信公众号

有课学公众号
  • 微信公众号: geekdaxue