代码之家  ›  专栏  ›  技术社区  ›  Trip

将var从一个扩展函数传递给另一个扩展函数

  •  0
  • Trip  · 技术社区  · 14 年前

    我无法通过的URL $.PhotoUpdater.doUpdate(url) doUpdate 功能。

    Firefox返回此错误:

    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}");
    
    1 回复  |  直到 14 年前
        1
  •  3
  •   Tim Down    14 年前

    您需要将函数传递到 window.setTimeout ,不是调用函数的结果:

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