2010-09-30 7 views
0

Je rencontre des problèmes pour passer l'URL de $.PhotoUpdater.doUpdate(url) à la fonction doUpdate.Passer une variable d'une fonction étendue à une autre

Firefox renvoie cette erreur:

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

mon code:

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

Comment je l'appelle:

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

Répondre

3

Vous devez passer une fonction dans window.setTimeout, pas le résultat de l'appel d'une fonction:

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