Skip to content

Instantly share code, notes, and snippets.

@viebel viebel/nameOfArgs
Created Feb 27, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.