Answers for "constructor in typescript"

5

classes in typescript

class Info {
  private name: string ;
  constructor(n:string){
    this.name = n ;
  };
  describe(){
    console.log(`Your name is  ${this.name}`);
  }
}

const a = new Info('joyous');
a.describe();
Posted by: Guest on October-17-2020
1

constructor in typescript

class Car { 
   //field 
   engine:string; 
 
   //constructor 
   constructor(engine:string) { 
      this.engine = engine 
   }  

   //function 
   disp():void { 
      console.log("Engine is  :   "+this.engine) 
   } 
}
Posted by: Guest on April-10-2021
0

how to extend ts class

class Animal {
  move(distanceInMeters: number = 0) {
    console.log(`Animal moved ${distanceInMeters}m.`);
  }
}

class Dog extends Animal {
  bark() {
    console.log("Woof! Woof!");
  }
}

const dog = new Dog();
dog.bark();
dog.move(10);
dog.bark();Try
Posted by: Guest on October-31-2020

Code answers related to "TypeScript"

Browse Popular Code Answers by Language