How to call one controller function from another controller function in Lightning?

I think that the better approach would be to try to extract whatever it is that you need to call in that controller function into the helper and call the helper. The helpers exist to enable sharing code within a component. Do you have a use case where that wouldn't work?

Just for fun, inspecting the action object the following would work:

var action = component.get("c.bar");
action.$meth$();

Obviously don't do that! :)


Lightning has been enhanced with a way to call a controller function after this question was posted in 2014.

You can declare the target controller function using the tag aura:method like below:

<aura:method name="barMethod" action="{!c.bar}" description="bar controller function" />

Then you can reference it on the controller:

({ bar : function(component, event, helper) { // Do something cool }, foo : function(component, event, helper) { // This is how you call bar() from here component.barMethod(); } })

If you need to pass a parameter other than those 3, you'll need to add an aura:attribute tag to the aura:method:

<aura:method name="barMethod" action="{!c.bar}" description="bar controller function"> <aura:attribute name="param1" type="the type" default="default value" /> </aura:method>

And the bar function needs to extract the parameter from the event like below:

var params = event.getParam( 'arguments' ); if( params ) { var param1 = params.param1; // rest of the code here }

See more at: Calling Component Methods


This is why Helpers exist as Peter correctly outlined above. We do know that there are a number of patterns in Aura that appear heavyweight but most have a logical justification. This specific case is one where I have a hard time explaining the why and we do have plans to streamline a number of things like this in the future (no ETA but I can say that we have the same complaint inside of Salesforce R&D).

You do not pass helper directly - Aura does that for you - this is just dependency injection which is a common pattern in many frameworks e.g. Angular.js