Get function parameter names for interface purposes

前端 未结 5 1283
灰色年华
灰色年华 2021-01-01 03:36

can anyone help me on how to retrieve function parameter names? For example:

var A = function(a, b, c) {};

I need to get the parameter name

5条回答
  •  甜味超标
    2021-01-01 04:15

    The only way would be to retrieve the function as a string and use a RegExp to get the parameter names:

    function test(a,b,c){/*function body*/}
    //=> this should return 'a,b,c':
    test.toString().replace(/(function.+\()(.+(?=\)))(.+$)/,'$2');
    

提交回复
热议问题