Test One:
var fud01 = function ()
{
var temp = 100;
This.temp = 200;
return temp + this.temp;
}
Alert (typeof (FUD01));
Alert (FUD01 ());
Operation Result:
Function 300
The most common way to use function is to set a JavaScript function. In a variable scope within a large expansion number, this refers to the owner of the FUD01.
Test Two:
var fud02 = new function ()
{
var temp = 100;
This.temp = 200;
return temp + this.temp;
}
Alert (typeof (FUD02));
Alert (Fud02.constructor ());
Run Result: Object 300
This is actually a user-defined object in JavaScript, but this is an anonymous class. This usage is basically not related to the use of the function itself, and a variable scope is constructed in the large expansion number, which refers to the scope itself.
Test Three:
var = new Function (' var temp = fud3; this.temp = $; return temp + this.temp; ');
Alert (typeof (FUD3));
Alert (FUD3 ());
Operation Result: function 300
Use the system built-in function object to build a function, and the first way in method one is exactly the same on both the effect and the initialization priority, that is, the function body is given as a string.
Test four:
var = Function (' var temp = fud4; this.temp = $; return temp + this.temp; ');
Alert (typeof (FUD4));
Alert (FUD4 ());
Operation Result: function 300
This method is not used frequently, the effect and method are the same, but it is unclear whether new to generate any side effects.
Explanation of new function () {} and function () {} ()
Function,new the difference between function,function,new function