Can I store JavaScript functions in arrays?

前端 未结 9 1909
时光说笑
时光说笑 2021-01-30 05:34

How can I store functions in an array with named properties, so I can call like

FunctionArray["DoThis"]

or even

Function         


        
9条回答
  •  暖寄归人
    2021-01-30 05:58

    You even can use a function as the name of the property:

    var func = function(a, b){alert(a+b)};
    var obj = {};
    obj[func] = 2;
    

提交回复
热议问题