Skip to content

Instantly share code, notes, and snippets.

@viebel
Created February 27, 2014 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viebel/9252577 to your computer and use it in GitHub Desktop.
Save viebel/9252577 to your computer and use it in GitHub Desktop.
In javascript, retrieve the names of the arguments
function namesOfArgs(fn) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm,
FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m,
FN_ARG_SPLIT = /,/,
fnText = fn.toString().replace(STRIP_COMMENTS, ''),
argDecl = fnText.match(FN_ARGS);
return argDecl[1].split(FN_ARG_SPLIT)
}
namesOfArgs(function(a,b,c,v) {}) // ['a','b','c','v']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment