-1
我想停止執行我的代碼2秒,以便所有正在進行的動畫都可以完成。我想打電話給使用的setTimeout的函數的Node.js是否有可能通過setTimeout調用自定義函數Node.js
我在我的代碼正在做的:
this.userActivity = function(a,b,side){
//some code of mine
setTimeout(this.doTheMagicIfPossible(this.scoringPossible),2000);
}
this. doTheMagicIfPossible = function(passedValue){
console.log("printing it out after 2 seconds"+passedValue);
}
但是,執行是沒有得到停止2秒鐘。
如果我這樣做:
setTimeout(this.doTheMagicIfPossible,2000,this.scoringPossible);
執行是越來越減少2秒停止,但功能沒有得到this.scoringPossible,它未定義在這種情況下。
少用魔法:'var me = this; setTimeout(function(){me.doTheMagicIfPossible(me.scoringPossible)},2000);''在哪裏'me'用於在稍後引用'this',它可能已經改變。 – Phrogz