ts中类的继承
定义类 class Person { name: string; //属性 constructor(_name: string) { this.name = _name; } //构造函数 sayHello(): string { return "Hi,everyone" } //方法 } let firstOne = new Person("Fred") //实例化类 继承 :继承使用关键字extends,调用父类使用super,子类继承父类的属性和方法,并且子类可以改写父类的属性和方法 class Animal { name: string; constructor(_name: string) { this.name = _name; } skinColour(color: string = "black"): void { console.log(`${this.name} skin colour is ${color}`) } } class Horse extends Animal { constructor(name: string) { super(name) } skinColour(color: string = "brown"): void { console.log(`I'am ${this.name}`); super.skinColour("brown"