문제

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?

도움이 되었습니까?

해결책

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

다른 팁

You can do it by iterating over the members of the window object:

for (var name in window) {
    if (name.match(/^_func/) && typeof window[name] == 'function') {
        console.log(name);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top