Saturday, February 15, 2020

Typescript

 










Example:

class Animal {

    move(distanceInMeters: number) {
    console.log(`Animal moved`+distanceInMeters);

    }
}

class Dog extends Animal {

    bark()
         {
          console.log('Woof! Woof!');
         }

}

const dog = new Dog();

dog.bark();

dog.move(10);

dog.bark();


Public, private, and protected modifiers:


class Animal {

public name: string;

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

public move(distanceInMeters: number)
{
  console.log(`${this.name} moved ${distanceInMeters}m.`);
}
}




Module:












Inherit One Class functions or variables into other class is called  Inheritance.

(or) inheritance  is the concept that when a class , any subclass that is defined can inherit the definitions

export class ZipCodeValidator
{ 
 isAcceptable(s: string): boolean;
}

class ZipCode
 { 
 getZip (s: string):string;
 }

No comments:

Post a Comment