美文网首页
typeScripte 中 extends 和implement

typeScripte 中 extends 和implement

作者: 小李不小 | 来源:发表于2021-07-17 15:55 被阅读0次

extends用来继承类,implements用来实现一个接口

  • extends案例
  interface Person{
    money:number
  }
//implements是对某个接口的实现,必须满足接口的类型规范
  class Father implements Person {
    public money: number = 1000
  }
//extends是对某个类的继承,可获取父类的所有的静态属性
  class Son extends Father {
    constructor() {
      super();
    }
    getMoney(): void {
      console.log(this.money,333);
    }
  }
  const son=new Son()
  son.getMoney()
}

相关文章

网友评论

      本文标题:typeScripte 中 extends 和implement

      本文链接:https://www.haomeiwen.com/subject/gphmpltx.html