0

I am trying to call a helper function from within another helper function, I read on this post that using this from within the helper function should grab the context of the object and I should be able to call the other function, but for some weird reason it doesnt work.

mycomponentController.js

window.addEventListener('message', helper.handleEvent)

mycomponentHelper.js

({
    handleEvent: function(event){
        this.otherFunction(); // This doesnt run no errors or anything
        console.log("Event handeled");
    },
    otherFunction: function(component){
        // None of this runs
        console.log("Scrolling to top of page");
        component.find('scrollerView').scrollTo('top');
    }
})

My best guess as to why its not working is because of the fact that I am not calling the first helper function, I am binding it to the event listener. I feel like that has something to do with it.

1

in your handleEvent, you should pass not only the event, but also the component, and in your handleEvent method, you should pass the component reference

this.otherFunction(component);

and from whatever method where your helper is being called, you should also pass the component as a reference:

helper.handleEvent(component, event);
| improve this answer | |
  • I edited my post sorry, it has been fixed and the problem still persist – Kevin Hernandez May 14 '19 at 1:01
  • component doesnt exist – Kevin Hernandez May 14 '19 at 1:03
  • you will have to share mycomponentController, i from there you should be passing the component and referencing the helper – glls May 14 '19 at 1:05
  • Yeah, im always doing weirsd stuff, thank you though. – Kevin Hernandez May 14 '19 at 1:06
  • Let us continue this discussion in chat. – Kevin Hernandez May 14 '19 at 1:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.