我想以下代码:
jQuery("#mybutton").click(function(){
//do something
});
Run Code Online (Sandbox Code Playgroud)
我怎么能记得这个函数"匿名"?,我不能给这个函数命名:
var xfun = function(){
//do something
}
jQuery("#mybutton").click(xfun);
Run Code Online (Sandbox Code Playgroud)
我可以这样做:
var working = false;
jQuery("#mybutton").click(function(){
if (working){
var _this = this;
_this._eventType = e.type;
setTimeout(function() { jQuery(_this).trigger(_this._eventType); }, 200);
return false;
}
//do something
});
Run Code Online (Sandbox Code Playgroud)
我需要的是这样的事情:
var working = false;
jQuery("#mybutton").click(function(){
if (working){
setTimeout( this_function, 200);
return false;
}
//do something
});
Run Code Online (Sandbox Code Playgroud)
谢谢.
编辑:
解:
jQuery("#mybutton").click(function(){
if (working){
var fn = arguments.callee;
var _this = this;
setTimeout(function(){fn.call(_this);}, 200);
return false;
}
//do something
});
Run Code Online (Sandbox Code Playgroud)
Cre*_*esh 20
你确实可以命名你的匿名函数:
jQuery("#mybutton").click(function doWork(){
if (working){
setTimeout(doWork, 200);
return false;
}
//do something
});
Run Code Online (Sandbox Code Playgroud)
您还可以使用arguments.callee:
jQuery("#mybutton").click(function(){
if (working){
setTimeout(arguments.callee, 200);
return false;
}
//do something
});
Run Code Online (Sandbox Code Playgroud)
我和前者一起去.
| 归档时间: |
|
| 查看次数: |
13696 次 |
| 最近记录: |