cancel
Showing results for 
Search instead for 
Did you mean: 

Aikau sleep wait method

redraccoon
Star Contributor
Star Contributor

Hello 

I would like to have a sleep method in my aikau widget

navigateTo : function com_widget__navigateTo(urlToGo){
console.log(this);
setTimeout(function() {

                                 this.myMethod();

                                 console.log(this);
                                 },1000) ;

}

********************************************

but it's not working, I have an error that say "this.myMethod doesn't exist"

It's not working only when I call my method inside the setTimeout function ... so as you can see I put two console.log(this) to see the problem, and they are not related to the same "this" wich I don't understand

the object is "this" in the widget and the window is "this" inside the method

1 ACCEPTED ANSWER

redraccoon
Star Contributor
Star Contributor

navigateTo : function com_widget__navigateTo(urlToGo){

      var aikauThis = this;
      console.log(this);
      setTimeout(function() {
      aikauThis.alfServicePublish("ALF_NAVIGATE_TO_PAGE", {
            url: urlToGo
      });
},3000) ;

}

View answer in original post

1 REPLY 1

redraccoon
Star Contributor
Star Contributor

navigateTo : function com_widget__navigateTo(urlToGo){

      var aikauThis = this;
      console.log(this);
      setTimeout(function() {
      aikauThis.alfServicePublish("ALF_NAVIGATE_TO_PAGE", {
            url: urlToGo
      });
},3000) ;

}