Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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).

like image 661
Vlad Dekhanov Avatar asked Jan 20 '14 17:01

Vlad Dekhanov


1 Answers

Use this :

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

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

secondMethod= () => {
   this.firstMethod();
}
like image 110
Denys Séguret Avatar answered Oct 13 '22 00:10

Denys Séguret