您可以将函数定义作为字符串传递给eval()函数,然后在调用时使用函数名即可。例如:

let my_function_str = "function my_function(a, b) { return a + b; }";
eval(my_function_str);

let result = my_function(2, 3);
console.log(result); // 输出5

注意,eval()函数可能存在安全风险,因此应谨慎使用。


原文地址: https://www.cveoy.top/t/topic/cyfZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录