(function() { // 父类 class Animal { name:string; color:string; constructor(name:string,color:string) { this.name = name; this.color = color; } eat() { console.log("好吃爱吃多吃") } } // 猫 class Cat extends Animal { age:number; /** * 若子类继承父类 * 子类的构造函数中必须对父类的构造函数进行重写 */ constructor(a:string,b:number,c:string) { super(a,c); this.age = b; } } let animal = new Animal("猫",'白'); let cat = new Cat('妹妹',3,'黄') console.log(animal) console.log(cat) })()