创建Function类型 前面加new和不加new有什么区别?
下满两段代码执行结果一样,Function 前面 加new和不加new有什么区别//代码1
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT text/language="JavaScript">
function dwf(s)
{
document.write(s+"<br/>")
}
var squre=new Function("x","return x*x");
dwf(squre(3));
dwf("testfunction begin")
function testfunction(a,b,c,f)
{
return f(a,b,c);
}
<BODY>
<SCRIPT text/language="JavaScript">
function dwf(s)
{
document.write(s+"<br/>")
}
var squre=new Function("x","return x*x");
//这里的Function前加new和不加new有什么区别
dwf(squre(3));
dwf("testfunction begin")
function testfunction(a,b,c,f)
{
return f(a,b,c);
dwf(testfunction(1,2,3,new Function("a,b,c","return a+b+c")))
//这里的Function前加new和不加new有什么区别
dwf("testfunction end")
document.write("End"+"<br/>");
</SCRIPT>
</BODY>
</HTML>
//代码2
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<SCRIPT text/language="JavaScript">
function dwf(s)
{
document.write(s+"<br/>")
}
var squre=new Function("x","return x*x");
dwf(squre(3));
dwf("testfunction begin")
function testfunction(a,b,c,f)
{
return f(a,b,c);
}
dwf(testfunction(1,2,3,new Function("a,b,c","return a+b+c")))
dwf("testfunction end")
document.write("End"+"<br/>");
</SCRIPT>
</BODY>
</HTML>