Per il seguente script, come posso scrivere una funzione che restituisce tutte le funzioni dello script come una matrice? Mi piacerebbe restituire una serie di funzioni definite nello script in modo che possa stampare un riepilogo di ogni funzione definita nello script.Restituisce tutte le funzioni definite in un file Javascript
function getAllFunctions(){ //this is the function I'm trying to write
//return all the functions that are defined in the script where this
//function is defined.
//In this case, it would return this array of functions [foo, bar, baz,
//getAllFunctions], since these are the functions that are defined in this
//script.
}
function foo(){
//method body goes here
}
function bar(){
//method body goes here
}
function baz(){
//method body goes here
}
Per chiarire, getAllFunctions() dovrebbe solo re trasforma le funzioni che sono definite nello script stesso e nient'altro. –
Ho chiarito la domanda originale in modo che la domanda non sia più ambigua. –
Vedere questo post http://stackoverflow.com/questions/493833/list-of-global-user-defined-functions-in-javascript – anazimok