I have the following code in my controller:
doInit: function(component, event, helper) {
// Create the action
var action = component.get("c.getExpenses");
// Add callback behavior for when response is received
action.setCallback(this,
response => this.cbFunction(component, response));
$A.enqueueAction(action);
},
cbFunction: function(component, response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.expenses", response.getReturnValue());
}
},
but I get the following error:
This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'cbFunction' of undefined] Callback failed: apex://ExpensesController/ACTION$getExpenses Failing descriptor: {c:expenses}
If I go back to the original code of placing the cb inside doInit, it works just fine, so it's not anything in the code, but rather after I extracted the cb function.