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)
{
}
 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Soundharyaa,

I found this link that has a small implementation of a similar scenario can you please have a look at it once:

>> https://salesforce.stackexchange.com/questions/82149/lightning-components-can-helpers-call-other-helpers

The implementation mentioned in above link is:

Component:
<aura:component > <input type="button" onclick="{!c.buttonClicked}" value="Click Me" id="myButton" /> </aura:component>
Controller:
({
               buttonClicked : function(component, event, helper) 
               { 
                helper.changeMyLabel(component, event.target.id); 
                }
})
Helper:
({
    changeMyLabel : function(component, buttonId) 
    {
        var newLabel = 'My Label Changed';
        this.changeButtonLabel(component, buttonId, newLabel);  
    },
    changeButtonLabel : function(component, buttonId, newLabel)
    {
        document.getElementById(buttonId).value = newLabel;
    }
})

I hope this helps and in case if this comes handy can you please choose this as the 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);

}