There are multiple methods for defining functions in js, and the direct quantity of functions is one of them. For example, varfunfunction () {}. If function is not assigned to fun, it is an anonymous function. Okay. Let's see how anonymous functions are called.
1. Call the function to obtain the returned value after execution
Js Code
The Code is as follows:
// Method 1: Call the function to obtain the returned value. Forced operator for function call execution
(Function (x, y ){
Alert (x + y );
Return x + y;
} (3, 4 ));
Js Code
// Method 2: Call the function to obtain the returned value. Force the function to execute directly and return a reference, and then call and execute the reference.
The Code is as follows:
(Function (x, y ){
Alert (x + y );
Return x + y;
}) (3, 4 );
2. Ignore the returned value after execution
Js Code
The Code is as follows:
// Method 3: Call a function and ignore the returned value
Void function (x ){
X = X-1;
Alert (x );
} (9 );
// Method 3: Call a function and ignore the returned value
The Code is as follows:
Void function (x ){
X = X-1;
Alert (x );
} (9 );
Well, let's look at the wrong call method.
Js Code
// Incorrect call Method
The Code is as follows:
Function (x, y ){
Alert (x + y );
Return x + y;
} (3, 4 );