简体   繁体   English

如何在不使用eval()的情况下将完整功能字符串转换为javascript函数

[英]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.

相关问题 如何在不使用 eval 的 javascript class 方法中检查变量是否为 function - How to check if variable is function in a javascript class method without using eval 如何在不使用 JavaScript 内置函数的情况下将字符串大写转换为小写 - How to convert the string uppercase to lowercase without using inbuilt function in JavaScript 如何在没有eval()的情况下执行存储为字符串的函数 - How to execute function stored as a string without eval() 如何评估字符串函数并在JavaScript中返回值? - How to eval string function and return value in javascript? 在函数字符串上使用 eval - Using eval on a function string 将字符串更改为 javascript 中的函数(不是 eval) - changing string to a function in javascript (not eval) Firefox扩展中的javascript字符串(不带eval(),setTimeout或新函数) - String to javascript in Firefox extension (without eval(), setTimeout or new Function) 如何在不带eval的情况下执行以字符串形式传递给JS函数的函数调用? - How to execute function calls that passed in JS function as string without eval? JavaScript,在不使用eval的情况下将私有函数作为公共方法内的字符串调用(Revealing pattern) - JavaScript, call private function as a string inside public method without using eval (Revealing pattern) (JavaScript) 在不使用 eval() 的情况下,编写一个 function 来确定写成字符串的两个数字之间的关系是否为真 - (JavaScript) Without using eval(), write a function that determines if the relation between two numbers written as a string is true
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM