Javascript函数计时器。没有按预期工作
问题:您好,我有点纠结于为什么setTimeout()在经过一段时间后不调用指定的函数。我尝试了一些方法,但似乎没有任何效果 解决方案:如果有人知道在特定时间后调用函数的任何其他方法 这是我的密码:Javascript函数计时器。没有按预期工作,javascript,function,time,Javascript,Function,Time,问题:您好,我有点纠结于为什么setTimeout()在经过一段时间后不调用指定的函数。我尝试了一些方法,但似乎没有任何效果 解决方案:如果有人知道在特定时间后调用函数的任何其他方法 这是我的密码: refreshStats: function(){ this.goldLabel.text = Math.floor(this.player.data.gold); this.attackLabel.text = Math.floor(this.playe
refreshStats: function(){
this.goldLabel.text = Math.floor(this.player.data.gold);
this.attackLabel.text = Math.floor(this.player.data.attack);
this.defenseLabel.text = Math.floor(this.player.data.defense);
if (this.player.questsDone.length > 0){
console.log(this.player.questsDone)
this.bpText.text = this.player.questsDone[this.player.questsDone.length-1];
setTimeout(this.FadeConsoleText(), 5000);
}
},
FadeConsoleText: function(){
console.log("log");
},
电流输出:
“探索”
“a”
想要的解决方案输出:
“探索”
(等待然后调用函数)
“a”
在advanced(高级)中感谢您希望传递函数,而不是函数返回到
setTimeout(设置超时)
:
setTimeout(this.FadeConsoleText, 5000);
看看所有这些问题: