Skip to content

Instantly share code, notes, and snippets.

@mediaupstream
Created August 28, 2011 08:38
Show Gist options
  • Select an option

  • Save mediaupstream/1176432 to your computer and use it in GitHub Desktop.

Select an option

Save mediaupstream/1176432 to your computer and use it in GitHub Desktop.
getFnArgs
/**
* Get the names of the arguments of any function
*/
var getFnArgs = function(fn){
var args = fn.toString().lines()[0];
return args.replace('function (', '').replace('){', '').split(', ');
};
// usage
var testFunction = function(foo, bar, baz){
// ... do stuff here
};
console.log( getFnArgs( testFunction ) );
// [ 'foo', 'bar', 'baz' ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment