三味线
三味线
Published on 2019-08-05 / 55 Visits
0
0

js 字符串作为函数运行

#js

1. new Function

var test = new Function("(function(){console.log('hello!')})()");

会在外面再包一层函数,获取不到返回值:

2. eval

var test = eval("(function(a, b){return a+b;})");

能获取返回值:


Comment