我正在尝试更多地了解 ES6,并在教程中看到了这门课。为什么前面goFast()
没有关键字就可以工作?function
这是类中函数的新简写,还是……?
class RaceCar extends Car { //inheritance
constructor(make, topSpeed) {
super(make); //call the parent constructor with super
this.topSpeed = topSpeed;
}
goFast() {
this.currentSpeed = this.topSpeed;
}
}
let stang = new RaceCar('Mustang', 150);
stang.printCurrentSpeed();
stang.goFast();
stang.printCurrentSpeed();