我有一些JS代碼如下;將參數傳遞給setTimeout回調函數
var x = self.someAJAXResponseJSON; // x has some object value here
setTimeout(function(x){
console.log("setTimeout ... : " + x); // But x is undefined here
}, 1000);
所以我想通過「x」到setTimeout回調函數。但是我在setTimeout中將「x」設置爲undefined。
我在做什麼錯?
使用Dojo JS
setTimeout(dojo.hitch(this, function(){
this.executeSomeFunction(x); // what shud be this
console.log("setTimeout ... : " + x); // But x is undefined here
}), 1000);
如果'變種x'被前面所定義的,是不是這種可能 - >'的setTimeout(函數(){ 的console.log( 「...的setTimeout:」 + X); },1000);'。從'callback'中刪除'x'並直接賦值? –
好吧,我認爲這種情況下的目標應該像創建具有不同_x_值的多個函數一樣。你能解釋一下更多@testndtv? – pietro909