Skip to content

Instantly share code, notes, and snippets.

@renorram
Last active June 21, 2016 14:16
Show Gist options
  • Save renorram/e53e4f2468a2f6bf7ebfe8b568706d48 to your computer and use it in GitHub Desktop.
Save renorram/e53e4f2468a2f6bf7ebfe8b568706d48 to your computer and use it in GitHub Desktop.
/**
* Return all the arguments of a specific function.
* @param func
* @returns {Array|{index: number, input: string}}
*/
function func_get_args(func) {
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
var ARGUMENT_NAMES = /([^\s,]+)/g;
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