Javascript Modular programming-immediate execution of functions (IIFE), javascriptiife
IIFE
Fully spell Imdiately Invoked Function Expression, the Function Expression to be executed immediately.
Syntax
Var module1 = (function () {var _ count = 0; var m1 = function (){//...}; var m2 = function (){//...}; return {m1: m1, m2: m2 };})();
Using the above Code, external code cannot read the internal _ count variable.
Meaning of parentheses
1,WrapFunction (){}Meaning of brackets
The purpose of the parentheses isFunction (){}Convert to an expression. Easy to execute. If this bracket is removed, an error is returned. Because simpleFunction (){}If it is not an executable expression, an error is reported.
2,Meaning of the second bracket
Explain understands the meaning of the first bracket. The second bracket is simple, that is, the execution expression.
Reference
$ (Fuction () {module1.m1 (); // call m1 ;});