typescript 学习第五天

接口扩展 接口可继承接口

第一种

interface Animal {
  eat():void;
}

interface Person extends Animal{
  work():void;
}

class Web implements Person{
  public name:string;
  constructor(name:string){
    this.name = name
  }
  eat(){
    console.log(this.name + '吃粮食')
  }
  work(){
    console.log(this.name + '敲代码')
  }
}
var w = new Web('老王');
w.eat()

第二种

interface Animal{
  eat():void;
}

interface Penson extends Animal{
  work():void;
}

class Programmer {
  public name:string;
  constructor(name:string){
    this.name = name
  }
  coding(code:string){
    console.log(this.name + code)
  }
}

class Web extends Programmer implements Person{
  constructor(name:string){
    super(name)
  }
  eat(){
    console.log(this.name + '吃粮食')
  }
  work(){
    console.log(this.name + '敲代码')
  }
}
var w = new Web('小王')
w.coding('敲代码')
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。