/* * Programming Quiz: Building Classes and Subclasses (2-3) */ class Vehicle { constructor(color = 'blue', wheels = 4, horn = 'beep beep') { this.color = color; this.wheels = wheels; this.horn = horn; } honkHorn() { console.log(this.horn); } } // your code goes here class Bicycle extends Vehicle { constructor(color, wheels, horn){ super(Vehicle); this.wheels = 2; this.horn = 'honk honk'; this.color = 'blue'; } } const myVehicle = new Vehicle(); myVehicle.honkHorn(); // beep beep const myBike = new Bicycle(); myBike.honkHorn(); // honk honk
测试答案如下
报错如下
为什么说Cannot read property 'name' of undefined?
橋本奈奈未
smileying