Home  >  Article  >  Web Front-end  >  js anonymous call implementation code_javascript skills

js anonymous call implementation code_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:51:30874browse

Okay, let's see how the anonymous function is called.
1. Function call to get return value after execution
Js code

Copy code The code is as follows:

//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
Copy the code The code is as follows:

(function(x,y){
alert(x y);
return x y;
})(3,4);



2. Ignore the return value after execution
Js code
Copy code The code is as follows:

//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
Copy the code The code is as follows:

void function(x) {
x = x-1;
alert(x);
}(9);

Well, finally look at the error Calling method
Js code
//Wrong calling method
Copy code The code is as follows:

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