1.ts中不支持继承多个类, 但是类可以作为接口来实现
// Person 类
class Person {
name: string;
sayHello() {
console.log("tag", `Helo ${this.name}!`);
}
}
// Student 类
class Student {
grade: number;
study() {
console.log("tag", " I need Study!");
}
}
class SmartObject implements Person, Student {
// Person
name: string = "person";
sayHello: () => void;
// Activatable
grade: number = 3;
study: () => void;
}
2.接口可以实现多继承
// 阿里接口
interface Ali {
pay: () => void;
}
// 腾讯接口
interface Tencent {
game: string;
play: () => void;
}
// 自己的接口
interface Self extends Ali, Tencent
// 这样谁implement Self的话就必须同事实现Ali和Tencent和Self定义的所有属性和方法