Vlad Dekhanov Vlad Dekhanov - 24 days ago 7
TypeScript Question

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

Answer

Use this :

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

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

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