-1

if we have :

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());
}

Any built-in method that retrieves name of nested functions: a,b,c . Let say :

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

}

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254

1 Answers1

0

DEMO

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;
    })
};

then :

 parent.closures()
 // ['a','b','c']
Community
  • 1
  • 1
Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254