arguments.callee替代

dag*_*da1 8 javascript

正如arguments.callee将要弃用的那样,我将在下面的表达式中使用而不是arguments.callee`:

var self = this;

this.async(function(){
  if(test()){
    then();
  }else{
    self.async(arguments.callee);
  }
});
Run Code Online (Sandbox Code Playgroud)

Flo*_*vic 5

这应该工作.但我不确定它是否适用于所有浏览器.

var self = this;

this.async(function someMethod(){
  if(test()){
    then();
  }else{
    self.async(someMethod);
  }
});
Run Code Online (Sandbox Code Playgroud)

  • 着名的[Kangax文章](http://kangax.github.com/nfe/)详细介绍了错误/怪癖,但一般来说它仍然有用. (2认同)