Created
February 27, 2014 15:42
-
-
Save viebel/9252577 to your computer and use it in GitHub Desktop.
In javascript, retrieve the names of the arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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