12

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

1 Answer 1

26

Use this :

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

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

secondMethod= () => {
   this.firstMethod();
}
Sign up to request clarification or add additional context in comments.

4 Comments

Sorry, but on my code second methhod calling from callback function. this indicate on data from calback context.
@VladDekhanov Edited with a solution to force the binding, as it seems to be what you want.
@dystroy @Vlad to be noted that super will not work with arrow functions
Is there in other alternative to "this", I my callBack function "this" says undefined after running the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.