Call a JavaScript function name using a string?

前端 未结 10 1113
孤独总比滥情好
孤独总比滥情好 2020-11-30 07:07

How can I hook up an event to a function name I have defined as a string?

I\'m using Prototype.js, although this is not Prototype-speficic.

$(inputId         


        
10条回答
  •  無奈伤痛
    2020-11-30 07:43

    Property accessors can be used to access any object's properties or functions.

    If the function is in the global scope, you can get it using the window object:

    var myFunc = window[myFuncName];
    

    This also works within the this scope:

    var myFunc = this[myFuncName];
    

提交回复
热议问题