This question already has an answer here:
这个问题在这里已有答案:
- How to execute a JavaScript function when I have its name as a string 30 answers
- 当我的名字作为字符串30答案时如何执行JavaScript函数
I have one function named root and at next part I am storing function name in variable (call) . I want to call function by using variable name For Example:-
我有一个名为root的函数,在下一部分我将函数名存储在变量(call)中。我想通过使用变量名来调用函数例如: -
(note:- not using root() using variable call's value )
(注意: - 不使用变量调用值的root())
call = "root";
root = function() {
name = "This is My root function";
console.log(name)
}
Can we call root function by value of variable (call) Is it possible.
我们可以通过变量值调用root函数(call)是否可能。
2 个解决方案
#1
2
Assuming call is a global browser variable, you can do:
假设call是一个全局浏览器变量,你可以这样做:
window[call]();
#1
2
Assuming call is a global browser variable, you can do:
假设call是一个全局浏览器变量,你可以这样做:
window[call]();