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
Soundhariyaa MSoundhariyaa M 

How to call a helper method from another helper method

Hi,

Suppose I have 

a:funtion(component,event)
{
},
b:function(component,event,page)
{
}
And I wanted to call b() from a() 
where page is a Integer.
How can I do this?
I tried the one given below but it didn't work
a:funtion(component,event)
{
    this.b(component,event,1);
},
b:function(component,event,page)
{
}
Can anyone help me
Best Answer chosen by Soundhariyaa M
David Zhu 🔥David Zhu 🔥
You would do this in a function.
a:funtion(component,event)
{
        var helper = this;
       …………
.      helper.b(component,event,1);

}

 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundariyaa,

As mentioned in this link: https://na93.salesforce.com/chatteranswers/ChatterAnswersQuestionSingleItem.apexp?id=9062I000000QwnU  can you please have a look at the implementation and in case if that helps can you please mark it as best answer so that it can be used by others in the future.

Regards,
Anutej
David Zhu 🔥David Zhu 🔥
You would do this in a function.
a:funtion(component,event)
{
        var helper = this;
       …………
.      helper.b(component,event,1);

}

 
This was selected as the best answer
Soundhariyaa MSoundhariyaa M
Hi David,

Instead this.b(component,event,1); I tried your solution.
But could you tell why this.b(component,event,1); didn't work and assigning this to helper variable and calling it using helper variable worked
 
David Zhu 🔥David Zhu 🔥
When "this" is used alone, it refers to global object. When "this" is used with this.methed, it refers to current object. Helper method is in global object.
You can treat controller method as  per instance, helper method is shared by instances. That is how controller and helper work.