1. new Function
var test = new Function("(function(){console.log('hello!')})()");
会在外面再包一层函数,获取不到返回值:
2. eval
var test = eval("(function(a, b){return a+b;})");
能获取返回值:
var test = new Function("(function(){console.log('hello!')})()");
会在外面再包一层函数,获取不到返回值:
var test = eval("(function(a, b){return a+b;})");
能获取返回值:
评论区