Vlad Dekhanov
Vlad Dekhanov

Reputation: 1084

Typescript: Calling method from another method of current class

Supposably, I have this class:

Class ExampleClass {  
    public firstMethod(){
     // Do something  
    }  
    public secondMethod(){
     //Do something with invoke firstMethod
    }
}

How can I invoke first method from another correctly? (Simple "firstMethod()" is not working).

Upvotes: 12

Views: 31441

Answers (1)

Denys Séguret
Denys Séguret

Reputation: 382130

Use this :

public secondMethod(){
   this.firstMethod();
}

If you want to force the binding to the instance, use the => operator :

secondMethod= () => {
   this.firstMethod();
}

Upvotes: 26

Related Questions