[SalesForce] How to call a method in a lightning component in same helper

I have a delay function in a lighting component helper from which I want to call another function I get the error [this.displayToast is not a function] how do I achieve this?

Delay function:

 callbackOnceAfterDelay : function(cmp, helper){
            var delay=60000; //1 min
            setTimeout(function() {
                console.log('Inside delay: ');
                        this.displayToast(cmp, 'success', 'Thanks');     
            }, delay);},

Function to call:

   displayToast: function(cmp, type, message, messageTemplate, templateData) {
        var toastEvent = $A.get('e.force:showToast');
        toastEvent.setParams({
            type: type,
            message: message,
            messageTemplate: messageTemplate,
            messageTemplateData: templateData
        });
        toastEvent.fire();
    }

Best Answer

I think this should do it:

callbackOnceAfterDelay : function(cmp, helper) {
    const self = this;
    const delay=60000; //1 min
    setTimeout(function() {
        console.log('Inside delay: ');
        self.displayToast(cmp, 'success', 'Thanks');     
    }, delay);
},

Just like in normal JS inside the setTimeout function this is not the helper context anymore. At least that is the explanation my limited JS knowledge can provide.

Unsure if the setTimeout will work without $A.getCallback to queue it up in lightning.

callbackOnceAfterDelay : function(cmp, helper) {
    const self = this;
    const delay=60000; //1 min
    window.setTimeout($A.getCallback(function() {
        console.log('Inside delay: ');
        self.displayToast(cmp, 'success', 'Thanks');     
    }), delay);
},