You need to sign in to do that
Don't have an account?
Jake Backues
difference between calling this and using the helper variable
In my helper js class, what is the difference between calling methods using the passed in helper from my parameters or calling a method using this? Is one better than the other? does one kick off a new asynchronous process and one stays synchronous with the current process?
({ doInit : function (component, event, helper) { helper.getContacts(component, event); this.getContacts(component, event); }, getContacts: function(component, event) { } })
I used the same code above.
I've talked with some Developer Group leaders and found out the answer to my question.
Turns out "this" and "helper" are exactly the same in the helper class. So there really is no need to pass the helper variable to your helper methods.
If you have a callback, you can declare a new variable as this and use that in the callback.
var helper = this;
action.setCallback(this, function(response){ helper.getContacts(); });
All Answers
Here are few things which you know.
- When you called like this.getContacts(component, event); then it call method of component controller.
- When you called like helper.getContacts(component, event); then it call method of helper.
- If we need to fetch data from sever side then we need to call helper.getContacts().
- If we need to get data from client side then we are calling this.getContacts().
I guess it will help you understand difference.Please mark it solved if it helps you.Thanks
Hemant
There is no way this.getContacts is calling the method of the controller. I don't have a method called that in the javascript controller or the apex controller. "this" definitely calls helper methods.
Actually "this" calls current class method if its in component's controller or it is in helper.So if you want to call method of current class then you can use this.
Thanks
Hemant
I tested that in a controller.js and it did not work.
Can you please share your code and explain what you are looking so i can help you better.
Thanks
Hemant
I used the same code above.
I've talked with some Developer Group leaders and found out the answer to my question.
Turns out "this" and "helper" are exactly the same in the helper class. So there really is no need to pass the helper variable to your helper methods.
If you have a callback, you can declare a new variable as this and use that in the callback.
var helper = this;
action.setCallback(this, function(response){ helper.getContacts(); });