JSFiddle - React, Tailwind, and code Playground
HTML
Extended answer to StackOvferlow question <a href="http://stackoverflow.com/questions/6921588">Is it possible to reflect the arguments of a javascript function</a>
<pre id="results"></pre>
JavaScript
function test0 (a, b, c) {};
function test1( a, b, c ) {};
function test2() {};
var test3 = function(){};
var test4 = function () {};
var test5 = "sfsf (a, b, c)";
var test6 = function(delay,
str = ' ',
str2 = ',',
json = { foo: 54, bar: true },
callback) {
setTimeout(() => {
callback({ foo: 42, bar: 'Yello timeout!', data: this.options });
}, delay * 1000);
};
var argRE = /^\s*function\s+(?:\w*\s*)?\((.*?)\)/;
document.getElementById('results').innerHTML = ([test0, test1, test2, test3, test4, test5, test6].map(
function (f, i) {
return (f.toString() + Array(32).join(' ')).slice(0, 30) +
' : <span style="color:green">' +
((f = f.toString().match(argRE))
? (f[1] ? '[' + f[1].trim().split(/\s*,\s*/) + ']'
: '[]') : null) +
'</span>';
})).join('\n');