<Span style = "font-size: 18px;"> function outerfn () {document. write ("outer"); var I = 0; function innerfn () {document. write ("inner"); I ++; document. write (I);} return innerfn;} // to use the inner () internal function, it cannot be used outside outerfn, direct reference </span> <span style = "font-size: 18px;"> outerfn () </span> <span style = "font-size: 18px; ">/// </span> <span style =" font-size: 18px; "> outerfn () </span> <span style =" font-size: 18px; ">;yes </span> <span style =" font-size: 18px; "> var innerobj = outerfn (); // set outerfn () the returned function variable is assigned to innerobj </span> <PRE name = "code" class = "JavaScript"> <span style = "font-size: 18px;"> innerobj (); // call an internal function </span> <span style = "font-size: 18px;"> outerfn </span> <span style = "font-size: 18px; "> () </span> <PRE name =" code "class =" JavaScript "> <span style =" font-size: 18px; "> innerobj (); </span> <span style = "font-size: 18px;"> // The second call to an internal function </span> <span style = "font-size: 18px; "> outerfn </span> <span style =" font-size: 18px; "> () </span> <span style =" font-size: 18px; "> </span>
We have recently studied closures and scope chains. Many concepts cannot be seen yet. It is not time to summarize them.
The above functional formula is often explained by closures and related knowledge examples. I can't see it before, but I understand it later, so hurry up and summarize this part.
Innerfn () is an internal function of outerfn (). to execute this internal function, it is impossible to apply innerfn () directly outside outerfn.
In the preceding example, the reference of the internal function is obtained through the return value of the parent function, and then the internal function is executed.
Internal function Parsing