【问题标题】:Javascript function timer. Not working as expected [duplicate]Javascript函数计时器。没有按预期工作[重复]
【发布时间】:2017-04-28 04:51:40
【问题描述】:

问题:您好,我有点不明白为什么 setTimeout() 在时间过去后不调用指定的函数我尝试了一些方法,但似乎没有任何效果

解决方案:如果有人知道在特定时间后调用函数的任何其他方式

这是我的代码:

      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");
      },

电流输出: “寻求” “一种” 想要的解决方案输出: “寻求” (等待然后调用函数) “一个”

谢谢你的进步

【问题讨论】:

标签: javascript function time


【解决方案1】:

你要传递函数,而不是函数返回的内容setTimeout

setTimeout(this.FadeConsoleText, 5000);

【讨论】:

    猜你喜欢
    • 2021-11-08
    • 2014-12-17
    • 2012-11-01
    • 2011-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    相关资源
    最近更新 更多