[英]how to convert a full function string to a javascript function without using eval()
I have a varible string like 我有一个像这样的可变字符串
var z = "anuj.working = false;anuj.downloadFile(event,'opp-for-download','anuj@anuj Demo Guide For Partners.pdf.zip (5.3 MB)','/file/dam/mail Anuj@anuj @Anuj Demo Guide For Partners.pdf.zip','zip',null)";
how can i convert it to a function. 我如何将其转换为函数。 i don't want to use eval().
我不想使用eval()。
You can declare the variable string as a new function, then call that function: 您可以将变量字符串声明为新函数,然后调用该函数:
var func = new Function(theFunctionString);
func();
I think this offers what you're looking for, but without having anuj.
我认为这提供了您正在寻找的东西,但是没有任何
anuj.
defined, I couldn't run a successful test. 定义,我无法运行成功的测试。
如果以JSON对象的方式进行连接,则可以使用JSON.parse将其转换为对象,从而可以将其作为对象的方法来调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.