Skip to content

Instantly share code, notes, and snippets.

@d6u
Created December 10, 2013 21:47
Show Gist options
  • Save d6u/7900833 to your computer and use it in GitHub Desktop.
Save d6u/7900833 to your computer and use it in GitHub Desktop.
JS Get Function Arguments' Name
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
function getParamNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(/([^\s,]+)/g);
if (result === null) result = [];
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment