首页 > 其他分享 >TypeScript的super

TypeScript的super

时间:2023-01-30 12:00:42浏览次数:41  
标签:TypeScript name age sayHello super string

(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();
})();

 

标签:TypeScript,name,age,sayHello,super,string
From: https://www.cnblogs.com/tanxwuwang/p/17075068.html

相关文章