Introduction to immediate execution function expressions in JavaScript
This article mainly introduces how to execute function expressions immediately in JavaScript. This article focuses on how to call function expressions immediately. For more information, see
We are used to seeing such an anonymous function.
The Code is as follows:
(Function (){
Console. log ("test ");
})();
Previously, self-executing anonymous function was called)
It turns out that there is another way to call the Function Expression Immediately (IIFE, Immediately-Invoked Function Expression)
Call function expression now
Compared with self-executed anonymous functions, the meaning of immediate call of function expressions is clearer.
Examples of Self-executed functions are as follows:
The Code is as follows:
Function foo () {foo ();}
And
The Code is as follows:
Var foo = function () {arguments. callee ();};
More importantly, the following may be self-executed anonymous functions.
The Code is as follows:
Var foo = function () {foo ();};