You can use RegEx (regular expressions) to get the arguments:
function viewmessage(username, name) {} var args = viewmessage.toSource() .match(/\((?:.+(?=\s*\))|)/)[0] .slice(1).split(/\s*,\s*/g);
Make sure that after ( or before ) you have no spaces. Otherwise, you can get this result:
function viewmessage( username, name ) {} var args = viewmessage.toSource() .match(/\((?:.+(?=\s*\))|)/)[0] .slice(1).split(/\s*,\s*/g);
Or you use trim() for each of the arguments after they are built:
args.forEach(function (e, i, a) {a[i] = e.trim();});
source share