源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

javascript 获取函数形参个数

  • 时间:2022-03-21 00:23 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:javascript 获取函数形参个数
/**
 * 获取函数的形参个数
 * @param {Function} func [要获取的函数]
 * @return {*}       [形参的数组或undefind]
 */
function getFuncParameters(func) {
  if (typeof func == 'function') {
    var mathes = /[^(]+\(([^)]*)?\)/gm.exec(Function.prototype.toString.call(func));
    if (mathes[1]) {
      var args = mathes[1].replace(/[^,\w]*/g, '').split(',');
      return args;
    }
  }
}
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部