开发者

Call javascript function which name is in variable [duplicate]

开发者 https://www.devze.com 2023-03-24 06:27 出处:网络
This question already has answers here: How to e开发者_Go百科xecute a JavaScript function when I have its name as a string
This question already has answers here: How to e开发者_Go百科xecute a JavaScript function when I have its name as a string (36 answers) Closed 6 years ago.

The problem is next: Assume that we have a select. Onchange event we need to call some function, but name of this function kept in variable. How to call this function ?


window[name]()

You can call functions by name reference by selecting them as a property of window and executing them


have you tried variableName(); ?

We often pass around callback functions, which might look something like this

function doSomething(callbackFunction){
    // some happy code
    callbackFunction()
}
0

精彩评论

暂无评论...
验证码 换一张
取 消