Skip to content

Instantly share code, notes, and snippets.

@huang-x-h
Last active August 29, 2015 14:07
Show Gist options
  • Save huang-x-h/7786399bc56698628ec9 to your computer and use it in GitHub Desktop.
Save huang-x-h/7786399bc56698628ec9 to your computer and use it in GitHub Desktop.
get function arguments name
// 摘自Secrets of the JavaScript Ninja
function argumentNames(fn) {
var found = /^[\s\(]*function[^(]*\(\s*([^)]*?)\s*\)/.exec(fn.toString());
return found && found[1] ? found[1].split(/,\s*/) : [];
}
argumentNames(function(x){})[0] === "x"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment