Search code examples
javascriptwebkitjavascriptcore

How to list all of javascript functions beginning with _func


Is it possible to list / return in an array all javascript functions in my own .js file that begin with the string "_func"?

Done in WebKit's JSCore.

Basically, if my file has a bunch of functions, how do I enumerate those functions?


Solution

  • You can loop through the members of the window object and test them:

    var functions = [];
    
    for( var x in window) {
        if(typeof window[x] === "function" && x.indexOf("_func") === 0) {
            functions.push(x);
        }
    }