使用JavaScript反射调用功能
我是JavaScript的新手,并且正在为Reflection在那里的工作方式挣扎。 我要做的是:给定一个函数名称的字符串,调用该函数。 例如,给出了var mystring =“ myFunctionName()”,然后我想以某种方式使用mystring调用myFunctionName()。
这是可能的吗?
提前致谢!
I am new to JavaScript and am struggling with how reflection works there.
What I want to do is: Given a String which is the function's name, invoke that function.
E.g. var myString = "myFunctionName()" is given and then I want to invoke myFunctionName() using myString somehow.
Is this possible and how?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这完全取决于声明函数的上下文。
对于浏览器的
窗口
上下文:It all depends on the context in which the function is declared.
For the browser's
window
context:您可以尝试:
You can try: