Last active
October 22, 2015 09:52
-
-
Save taotao365s/04ae47652b66e206525e to your computer and use it in GitHub Desktop.
get function arguments name in js
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
| function getArgs(func) { | |
| // 首先匹配函数括弧里的参数 | |
| var args = func.toString().match(/function\s.*?\(([^)]*)\)/)[1]; | |
| // 分解参数成数组 | |
| return args.split(",").map(function(arg) { | |
| // 去空格和内联注释 | |
| return arg.replace(/\/\*.*\*\//, "").trim(); | |
| }).filter(function(arg) { | |
| // 确保没有undefineds | |
| return arg; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment