js中new Function的用法

来源:互联网 发布:网络广告公司经营项目 编辑:程序博客网 时间:2024/05/20 06:23

转自:http://www.cnitblog.com/yemoo/archive/2007/09/25/34017.html


有一种用法比较特别:

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

输出:

function
300 

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

原创粉丝点击