-1

如果我们有:

function parent(){

  function a(){
     return 'i am a';
  }
  function b(){
      return 'i am b';
  }
  function c(e,f){
      console.log(e+f);
  }
  c(a(),b());
}

检索嵌套函数名称的任何内置方法: a,b,c 。让我们说:

 parent.closures()
 // ['a','b','c']

}

4

1 回答 1

0

演示

Function.prototype.closures=function() { 
    var that=this,fn = function(r) {
         //see demo==> to reduce non-functional code
    };
    return this.toString().split("\n").filter(function(d) {
        return d.indexOf('function ') !== -1
    }).map(fn).filter(function(f) {
        return f !== that.name;
    })
};

然后 :

 parent.closures()
 // ['a','b','c']
于 2014-06-04T19:14:12.237 回答