js中new Function的用法

来源:互联网 发布:java多线程,代码多的书 编辑:程序博客网 时间:2024/06/08 06:00

有一种用法比较特别:

var foo3 = new Function('var temp = 100; this.temp = 200; return temp + this.temp;');alert(typeof(foo3));alert(foo3()); 


输出:


function
300 

(new Function('...'))()将会执行引号中的内容,与eval效果差不多

0 0