将 var 从一个扩展函数传递到另一个扩展函数
我在传递 $.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}");
I am having trouble passing the url of $.PhotoUpdater.doUpdate(url)
to do the doUpdate
function.
Firefox returns this error :
useless setTimeout call (missing quotes around argument?)
[Break on this error] timer = setTimeout($.PhotoUpdater.doUpdate(url), 5000)
my 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"});
}
}
});
How I call it:
$.PhotoUpdater.startUpdate("#{@organization.id}", "#{@gallery.id}");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将函数传递到 window.setTimeout 中,而不是调用函数的结果:
You need to pass a function into
window.setTimeout
, not the result of calling a function: