我是学习 ES6 的新手,下面有以下代码。代码运行并执行正确的输出,但在我的控制台中我收到“无法读取未定义的属性‘名称’”。有人可以告诉我为什么会出现此错误。
class Vehicle {
constructor(color = 'blue', wheels = 4, horn = 'beep beep') {
this.color = color;
this.wheels = wheels;
this.horn = horn;
}
honkHorn() {
console.log(this.horn);
}
}
class Bicycle extends Vehicle{
constructor(color, wheels, horn){
super(color, wheels, horn);
this.wheels = 2;
this.horn = 'honk honk';
}
}
const myVehicle = new Vehicle();
myVehicle.honkHorn(); // beep beep
const myBike = new Bicycle();
myBike.honkHorn(); // honk honk