function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Answer plzAnswer plz 

Call one function of js into another function of same js

If there are two javascript methods fun1() and fun2() in same LWC component, is it possible to call method fun2() from fun1() where Function fun1() gets called with click of button? If not what can be the possible workaround for this?
AbhinavAbhinav (Salesforce Developers) 
Hi ,

Yes that seems possible.

You can refere below link where question  is almost similar to yours.

https://salesforce.stackexchange.com/questions/308085/how-to-call-one-function-from-another-function-in-same-javascript-file-in-lightn

Hope it helps.Please mark it as best answer so that other having same query find it useful.

Thanks!
Akshay Dhiman 63Akshay Dhiman 63
Hi,
Yes, you can call fun2() from fun1(). You can do this by using this keyword before the fun2().
export default class CallMethod extends LightningElement {
    fun1(){
        this.fun2();
    }
    fun2(){
        //do something
    }
}

Hope this explanation will resolve your query. Mark it as the best answer if you find it helpful.


Thanks
Akshay    

mukesh guptamukesh gupta
Hi,

Please follow below code: 
export default class CMD extends LightningElement {
  A() {
    this.B();
  }
  B() {
    // do something //
  }
}


if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh