[removed] function call to itself

后端 未结 2 1294
难免孤独
难免孤独 2021-01-02 16:21

I suppose the following code:

jQuery(\"#mybutton\").click(function(){

    //do something

});

How could I recall to this function \"anonym

相关标签:
2条回答
  • 2021-01-02 16:45

    You can indeed name your anonymous function:

    jQuery("#mybutton").click(function doWork(){
      if (working){
        setTimeout(doWork, 200);
        return false;
      }
      //do something    
    });
    

    You can also use arguments.callee:

    jQuery("#mybutton").click(function(){
      if (working){
        setTimeout(arguments.callee, 200);
        return false;
      }
      //do something    
    });
    

    I'd go with the former.

    0 讨论(0)
  • 2021-01-02 16:53

    Can you explain why you can't name the function? You can use arguments.callee to get a reference to the current function, but that is deprecated and I'm not sure how much support it has among current browsers.

    0 讨论(0)
提交回复
热议问题