Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将变量从一个扩展函数传递到另一个扩展函数_Javascript_Jquery_Function_Extend - Fatal编程技术网

Javascript 将变量从一个扩展函数传递到另一个扩展函数

Javascript 将变量从一个扩展函数传递到另一个扩展函数,javascript,jquery,function,extend,Javascript,Jquery,Function,Extend,我无法通过$.PhotoUpdater.doUpdate(url)的url来执行doUpdate功能 Firefox返回以下错误: useless setTimeout call (missing quotes around argument?) [Break on this error] timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000) 我的代码: $.extend({ PhotoUpdater: { startUp

我无法通过
$.PhotoUpdater.doUpdate(url)
的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}");
我怎么称呼它:

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

您需要将函数传递到
窗口。setTimeout
,而不是调用函数的结果:

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

您需要将函数传递到
窗口。setTimeout
,而不是调用函数的结果:

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