Analyzing empty function javascript

    function isEmptyFunction(fun){
      let reg = /^function\s*[\w\$]*\s*\([\s\w\$,=]*\)\s*\{\s*\}\s*$/;
      return typeof fun === 'function' && reg.test(fun.toString());
    }
    
    // 支持以下空函数
    // 1、
    isEmptyFunction(function(){});
    // 2、
    isEmptyFunction(function (  a,b,c)   {  });
    // 3、
    isEmptyFunction(function (  a,b = 3,c)   {  });
    // 4、
    isEmptyFunction(function funName(){});
    // 5、
    isEmptyFunction(function    f2A3u23nNa$$_me222     (      )     {       });
    

Small micro-channel enhancement compiler program determines if the opening of the third method not supported

Guess you like

Origin www.cnblogs.com/zhuangkaixing/p/12016109.html