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