zl程序教程

您现在的位置是:首页 >  前端

当前栏目

javascript获取函数形参个数

JavaScript 函数 获取 个数 形参
2023-06-13 09:15:40 时间
/**
*获取函数的形参个数
*@param{Function}func[要获取的函数]
*@return{*}[形参的数组或undefind]
*/
functiongetFuncParameters(func){
if(typeoffunc=="function"){
varmathes=/[^(]+\(([^)]*)?\)/gm.exec(Function.prototype.toString.call(func));
if(mathes[1]){
varargs=mathes[1].replace(/[^,\w]*/g,"").split(",");
returnargs;
}
}
}