来源: GItHub地址
1. What's the output?
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor;
return this.newColor;
}
constructor({ newColor = "green" } = {}) {
this.newColor = newColor;
}
}
const freddie = new Chameleon({ newColor: "purple" });
freddie.colorChange("orange");
- A:
orange
- B:
purple
- C:
green
- D:
TypeError
答案:D
解析:colorChange函数是一个static函数,static函数仅作用于创建它的构造函数上,并且不能传递给任何子方法;freddie方法是一个子函数,不会继承color