Recent projects have encountered this problem, by the way record!
Find the information on the Internet to understand understanding, give my understanding as follows:
Question 1:
(function () {}) (): This function () {} represents an anonymous one, and () wraps the functions () {}, () representing the highest priority execution, which takes precedence over the function () {}. The last () means that the function () { } is called immediately after executing function () {}.
Like what:
If function () {} is compared to function xx () {}, () represents XX (), the defined XX function is called.
Case:
(function () {
Alert (0)
})();
Result: the frame shows 0;
(function () {
Alert (0)
});
Results: no box display 0;
Question 2:
xx=xx| | {};//means declaring a command space called XX (Defining a global variable--in JavaScript, variables that are not declared with VAR are treated as global variables ).
xx.kk= (function () {
Xx.yy=function () {///Declare a namespace called XX.YY (the object in the closure is passed to the global variable through the addition of the global variable, which results in a code encapsulation
return "XXX";
};
var data1= "";
(function () {
data1= "XXX";
})();
return {DATA1:DATA1};
})();
-----------Call
Alert (Xx.yy ());
Or
alert (XX.KK.DATA1);
(function () {}) ();, xx=xx| | {}; the definition and role!