js 执行字符串的函数
1.使用new Function 点击查看文档
var func = 'function test(_this,res){console.log(res,"===",_this)}';
var _this = "_this";
var res = {name:'***',age:'21',sex:1,list:[1,2,3]}
function Func(func,res){
var dom = new Function(`return ${func}`)();
console.log(dom,'dom');
dom && dom(_this,res);
}
Func(func,res);
2.使用eval 点击查看文档
eval("console.log(1111111111)");

浙公网安备 33010602011771号