2010-09-30 136 views
0

我無法通過$.PhotoUpdater.doUpdate(url)的URL來執行doUpdate函數。將var從一個擴展函數傳遞到另一個

火狐返回此錯誤:

useless setTimeout call (missing quotes around argument?) 
[Break on this error] timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000) 

我的代碼:

$.extend({ 
    PhotoUpdater: { 

    startUpdate: function(organization, gallery){ 
     url = "/organizations/" + organization + "/media/galleries/" + gallery + "/edit_photo_captions" 
     timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000) 
    }, 
    stopUpdate: function(){ 
     clearTimeout(timer); 
     timer = 0; 
    }, 
    doUpdate: function(url){ 
     $.ajax({type: "GET", url: url, dataType: "script"}); 
    } 
    } 
}); 

我怎麼稱呼它:

$.PhotoUpdater.startUpdate("#{@organization.id}", "#{@gallery.id}"); 

回答

3

你需要一個函數傳遞到window.setTimeout,不是調用函數的結果:

startUpdate: function(organization, gallery){ 
    url = "/organizations/" + organization + "/media/galleries/" + gallery + "/edit_photo_captions"; 
    timer = window.setTimeout(function() { 
     $.PhotoUpdater.doUpdate(url) 
    }, 5000); 
},