This new version also supports arrow functions ...
args = f => f.toString ().replace (/[\r\n\s]+/g, ' '). match (/(?:function\s*\w*)?\s*(?:\((.*?)\)|([^\s]+))/). slice (1,3). join (''). split (/\s*,\s*/); function ftest (a, b, c) { } let aftest = (a, b, c) => a + b / c; console.log ( args (ftest),
Here is what I think you are looking for:
function ftest (a, b, c) { } var args = ftest.toString (). replace (/[\r\n\s]+/g, ' '). match (/function\s*\w*\s*\((.*?)\)/)[1].split (/\s*,\s*/);
args will be an array of test argument names ie ['a', 'b', 'c']
The args value will be an array of parameter names if ftest is a function. The array will be empty if ftest has no parameters. The args value will be null if ftest does not match the regular expression, i.e. this is not a function.
HBP Aug 03 2018-11-11T00: 00Z
source share