reflection - Return all of the functions that are defined in a Javascript file -


for following script, how can write function returns of script's functions array? i'd return array of functions defined in script can print summary of every function defined in script.

    function getallfunctions(){ //this function i'm trying write         //return functions defined in script         //function defined.         //in case, return array of functions [foo, bar, baz,         //getallfunctions], since these functions defined in         //script.     }      function foo(){         //method body goes here     }      function bar(){         //method body goes here     }      function baz(){         //method body goes here     } 

declare in pseudo namespace, example this:

   var mynamespace = function(){     function getallfunctions(){        var myfunctions = [];       (var l in this){         if (this.hasownproperty(l) &&              this[l] instanceof function &&             !/myfunctions/i.test(l)){           myfunctions.push(this[l]);         }       }       return myfunctions;      }       function foo(){         //method body goes here      }       function bar(){          //method body goes here      }       function baz(){          //method body goes here      }      return { getallfunctions: getallfunctions              ,foo: foo              ,bar: bar              ,baz: baz };      }();     //usage     var allfns = mynamespace.getallfunctions();     //=> allfns array of functions.      //   can run allfns[0]() example 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -