1.function A () {}
The definition of this method is global, even if the definition after the call, the system will not complain, it can be understood that the system in the implementation of the method to find the definition of the location to initialize.
2.var a=function () {}
The method of defining the anonymous function, if invoked before the definition, will have an error. It can be understood that only when you run to this method can you initialize the variable a, and if you do not initialize the variable A, an error is made. At this point, a represents the return value of the following anonymous function.
3.var a=new function () {}
In JavaScript, a method is treated as a class, which is defined by a class with a table that is the method itself.
But there is a special case in which, if the return value is an array, method, or other class in the method, then a does not represent the method, but rather represents the new class that is returned.
Scenario One:
var a = new function () {return "center"};
alert (a);
We run the story one code, and it returns "[Object Object]", which is equivalent to:
function X () {
return "center";
}
var a = new X ();
Alert (a): We have transformed the code of scenario one into the following.
var a = new function () {return new String ("Center")};
alert (a);
We run, we will find that the return is "center", which is why.
If a Reference object (array, object, function, etc.) is returned after the new expression, it overrides the anonymous object created by new, and returns a primitive type (return-original type undefined) if returned (returns are not in fact). Anonymous object created by new
Because the new string constructs an object, rather than a String, and the new string (x) takes an argument, then alert it returns x. So yx01 returns the object of the new String ("center"), and alert yx01 displays the "center of the circle."
Scenario Two:
var a = function () {return "center"} ();
alert (a); We run the story code and return to the display "center of the Circle", which is equivalent to:
var x = function () {return "center"};
A = x ();
alert (a); Obviously, YX02 returns the execution result value of the anonymous function, which is yx02: "Center."