TypeScript的super

(function(){
class Animal{
  name:string;

  constructor(name:string){
    this.name=name;
  }

  sayHello(){

    console.log('动物再叫---');
    
  }


}
class Dog extends Animal {
  age:number;
  constructor(name:string,age:number){
    super(name);
    this.age=age;
  }
    sayHello() {
      // super.sayHello();

      console.log('汪汪汪!');
      
    }
}
const dog=new Dog('旺财',18);
dog.sayHello();
})();

 

posted @ 2023-01-30 11:54  勿_忘  阅读(20)  评论(0编辑  收藏  举报