I'm trying to learn more about ES6 and saw this class in a tutorial. Why does goFast()
work without a function
keyword in front of it? Is this a new shorthand for functions in classes, or…?
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();