Internal function Parsing

Source: Internet
Author: User
<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.