Skip to content

Instantly share code, notes, and snippets.

@taotao365s
Last active October 22, 2015 09:52
Show Gist options
  • Select an option

  • Save taotao365s/04ae47652b66e206525e to your computer and use it in GitHub Desktop.

Select an option

Save taotao365s/04ae47652b66e206525e to your computer and use it in GitHub Desktop.
get function arguments name in js
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