function getArgs(func) {
// 先用正则匹配,取得符合参数模式的字符串.
// 第一个分组是这个: ([^)]*) 非右括号的任意字符
var args = func.toString().match(/function\s.*?\(([^)]*)\)/)[1];
// 用逗号来分隔参数(arguments string).
return args.split(",").map(function(arg) {
// 去除注释(inline comments)以及空格
return arg.replace(/\/\*.*\*\//, "").trim();
}).filter(function(arg) {
// 确保没有 undefined.
return arg;
});
}
function myCustomFn(arg1, arg2,arg3) {
// ...
}
// ["arg1", "arg2", "arg3"]
console.log(getArgs(myCustomFn));
public class Test {
private String getMethodName() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[2];
String methodName = e.getMethodName();
return methodName;
}
public void getXXX() {
String methodName = getMethodName();
System.out.println(methodName);
}
public void getYYY() {
String methodName = getMethodName();
System.out.println(methodName);
}
public static void main(String[] args) {
Test test = new Test();
test.getXXX();
test.getYYY();
}
}
public static String getMethodName() {
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[2];
String methodName = e.getMethodName();
return methodName;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有