Js function calls can be performed in the following ways:
(1) Direct call of the named Function
Copy codeThe Code is as follows:
Function foo ()
{
}
Foo ();
(2) Anonymous functions are called through reference.
Copy codeThe Code is as follows:
FooRef = function ()
{
}
FooRef ();
(3) call an anonymous function that is not referenced 1
Copy codeThe Code is as follows:
(Function ()
{
}());
(4) Anonymous function calls not referenced 2
Copy codeThe Code is as follows:
(Function ()
{
})();
(5) Anonymous function calls not referenced 3
Copy codeThe Code is as follows:
Void function ()
{
}();
Figure 1.1 and Figure 1.2 show that the operation processes of these two expressions are different. In Figure 1.1, the mandatory operator is used to execute the function call operation, in Figure 1.2, a forced operator is used to calculate the expression "function Direct Volume Declaration", return a reference to the function itself, and then operate on the function reference through the function call operation. The last anonymous function called void function () {} (); is used to call the function and ignore the return value. The void operator is used to make the function expression following it perform operations. If we do not use "void" and force operation "()", can the code be executed:
(1) function () {} () // use ''()" to force call
(2) function () {}(); // use ";" to execute the statement
The script engine considers function () {} as a function declaration, which does not pass syntax detection. The code is parsed as follows:
Function (){};();
Function () {} is interpreted as a declaration, and "();" is interpreted as a separate line. Therefore, a syntax error is reported. Why do you know it is "(); "error? Let's change it to the following code:
Function () {}( 1 );
This will be interpreted by the engine:
Fucntion (){};
(1); // single value expression
Therefore, the syntax detection is passed...