The publishData() function won't work inside setTimeout() in my custom widget - returns error: this.publishData() is not a function. But this.publishData() works fine alone. How to get this.publishData() work inside setTimeout()?
Solved! Go to Solution.
Xuan,
Your issue is going to be a scope issue. The "this" object inside your setTimeout function is not scoped to the widget so this.publishData is not a function. You need to hitch your setTimeout function using lang.hitch.
setTimeout(lang.hitch(this, function(){
this.publishData(yourdata);
}), 200);
Xuan,
Your issue is going to be a scope issue. The "this" object inside your setTimeout function is not scoped to the widget so this.publishData is not a function. You need to hitch your setTimeout function using lang.hitch.
setTimeout(lang.hitch(this, function(){
this.publishData(yourdata);
}), 200);
Sharp answer, thank you!