Created
August 28, 2011 08:38
-
-
Save mediaupstream/1176432 to your computer and use it in GitHub Desktop.
getFnArgs
This file contains hidden or 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
| /** | |
| * 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