How to list all of javascript functions beginning with _func

筅森魡賤 提交于 2020-01-14 04:22:23

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/7378647/how-to-list-all-of-javascript-functions-beginning-with-func

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!