Typescript中接口的扩展,接口的继承
// Person接口
interface Person {
name: string;
eat(foot: string): void;
}
// Man接口继承Person接口
interface Man extends Person{
work(type: string): void;
}
class Web{
public name: string;
constructor(name: string) {
this.name = name;
}
cording(code: string) {
console.log(`${this.name} 在${code}`);
}
}
// BigMan 继承 Web 并实现 Person 接口
class BigMan extends Web implements Man {
eat(foot: string) {
console.log(this.name + '在吃' + foot);
}
work(type: string) {
console.log(this.name + '工作类型'+ type);
}
}
var bm = new BigMan("朱远航"); //
bm.eat("大虾"); // 朱远航在吃大虾
bm.work("打渔"); // 朱远航工作类型打渔
bm.cording("写代码"); // 朱远航 在写代码
还没有评论,来说两句吧...