Use JavaScript variable as function name?

前端 未结 5 1052
抹茶落季
抹茶落季 2020-12-02 00:23

I have the following code in Javascript:

jQuery(document).ready(function(){
    var actions = new Object();
    var actions;
    actions[0] = \'create\';
            


        
5条回答
  •  日久生厌
    2020-12-02 00:57

    You'll need a reference to the scope object in which you want to create the functions. If it's the global scope you can use window:

    window[ actions[key] + "Dialog" ] = function(){ ... }
    

提交回复
热议问题