ES6语法练习,继承,Cannot read property 'name' of undefined

/*
 * 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

测试答案如下

http://img.mukewang.com/5998f99f00011e7c08900530.jpg

报错如下

http://img.mukewang.com/5998f9b800012c2a05880293.jpg

为什么说Cannot read property 'name' of undefined?

无无法师
浏览 3089回答 2
2回答

橋本奈奈未

编译器的问题?我这边是可以的。你试试super()不传参数试试呢

smileying

class Bicycle extends Vehicle {   constructor(color, wheels = 2, horn = 'honk honk'){       super(color,wheels,horn);   }  }
打开App,查看更多内容
随时随地看视频慕课网APP