Skip to content

Instantly share code, notes, and snippets.

@demchenkoe
Created March 31, 2015 23:41
Show Gist options
  • Save demchenkoe/42819d0f094417c1f6ee to your computer and use it in GitHub Desktop.
Save demchenkoe/42819d0f094417c1f6ee to your computer and use it in GitHub Desktop.
Get javascript function param names.
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
function getFnParamNames(func) {
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
var result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
if(result === null)
result = [];
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment