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
Vivek Kumar 257Vivek Kumar 257 

Hello, Anyone please tell me how to call a js controller method in js helper in lightning component

Steven NsubugaSteven Nsubuga
Why would you want to do this? The recommended pattern is to call the helper from the controller, not the other way round..
Vivek Kumar 257Vivek Kumar 257

Thanks for reply,

I am trying to do the same because there is a function which is written in js controller method, and same thing i need to do in another method. So i don't want to write code again in that method as well.
And we can't call one method inside another method in js controller, but we can do the same in js helper.
So for reduce code i was trying to do that. I don't know it will be best practice or not.
Please suggest me best way to do that.

Steven NsubugaSteven Nsubuga
Move that method from the controller into the helper. Helper exists to facilitate code reuse. Any code that you want to reuse should be moved to the helper. It then becomes easy because the controller can call the helper.
Vivek Kumar 257Vivek Kumar 257
Ok, Thanks