How to get method name from JavaScript file

后端 未结 4 1536
终归单人心
终归单人心 2021-01-16 19:33

I have a JavaScript file with many methods defined in it. Is there any way to know how many methods are in that file & what are the names of methods?

4条回答
  •  一向
    一向 (楼主)
    2021-01-16 19:46

    While, in theory, you could try to find everything that matched the pattern:

    function (
    

    You'd be missing out on a lot of other types of functions. See, Functions are really just objects in JavaScript. They can be assigned, shared, modified, and moved around. So, you'd also have to find these:

    var  = function() {}
    

    And these:

    function returnFunc() {
        return function() {...}
    }
    var  = returnFunc();
    

    As well as these:

    obj.member = new Function();
    

    And a nearly infinite variety of similar function definitions.

    So, the answer is, most likely you can't. Unless the code is extremely narrowly constructed.

提交回复
热议问题