Okay, let's see how the anonymous function is called.
1. Function call to get return value after execution
Js code
//Method 1, call the function and get the return value. The coercion operator causes the function call to execute
(function(x,y){
alert(x y);
return x y;
}(3,4));
Js code
//Method 2, call the function and get the return value. Force the function to be executed directly and then return a reference. The reference is then called and executed
(function(x,y){
alert(x y);
return x y;
})(3,4);
2. Ignore the return value after execution
Js code
//Method 3, call the function and ignore the return value
void function(x) {
x = x-1;
alert(x);
}(9);
//Method three, call the function and ignore the return value
void function(x) {
x = x-1;
alert(x);
}(9);
Well, finally look at the error Calling method
Js code
//Wrong calling method
function(x,y){
alert(x y);
return x y;
}(3,4);
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn