new Function() with variable parameters

前端 未结 10 683
傲寒
傲寒 2020-12-25 11:38

I need to create a function with variable number of parameters using new Function() constructor. Something like this:

args = [\'a\', \'b\'];
bod         


        
10条回答
  •  清酒与你
    2020-12-25 12:11

    function construct(){
             this.subFunction=function(a,b){
             ...  
             }
    }
    var globalVar=new construct();   
    

    vs.

    var globalVar=new function (){
                  this.subFunction=function(a,b){
                  ...
                  }
    }
    

    I prefer the second version if there are sub functions.

提交回复
热议问题