(function () { class Animal { constructor(type, color) { this.type = type; this.color = color; } say() { console.log(`这有一只${this.type}`); } } /** * super 调用父类中的属性 * 若子类中添加新的属性 * 子类的构造器需要对父类的构造器中的属性使用super继承 */ class Child2 extends Animal { constructor(type, color, action) { super(type, color); this.action = action; } } let a = new Animal('小猫', '白'); let c = new Child2("小狗", '黑', '汪汪'); console.log(a); a.say(); console.log(c); })();