OK, let's see how anonymous functions are invoked.
1, after the execution of the return value of the function call
JS Code
Copy Code code as follows:
Mode 1, call the function, get the return value. The force operator makes the function call execute
(function (x,y) {
alert (x+y);
return x+y;
} (3,4));
JS Code
Mode two, call the function, get the return value. Force the function to perform a direct amount of execution and return a reference, and then invoke the execution
Copy Code code as follows:
(function (x,y) {
alert (x+y);
return x+y;
}) (3,4);
2. Ignore return value after execution
JS Code
Copy Code code as follows:
Mode three, call function, ignore return value
void function (x) {
x = x-1;
alert (x);
} (9);
Mode three, call function, ignore return value
Copy Code code as follows:
void function (x) {
x = x-1;
alert (x);
} (9);
Well, finally, look at the wrong way of calling.
JS Code
The wrong way to call
Copy Code code as follows:
function (x,y) {
alert (x+y);
return x+y;
} (3,4);