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)");



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM