A preliminary study on JavaScript function (vi)---closure

Source: Internet
Author: User
Tags closure

First, let's look at a function:

var a = ' global variable '= function () {    = ' local variable ';     = function () {         = ' inner local ';          return b            }      return N;  } Cosole.log (b)  //  b:is not defind;

The function f contains the local variable B, so B is not seen in the global space.

The function n has its own private space and can also access F () and global space, so variable B is visible to her.

Because F () is called in the global space (she is a global function), we assign her to another global variable, resulting in a new global function that can access the F () private space (any variable or other inside).

var inner =//  ' local variable ';

This is known as the use of closure breakout for chain!!!!!

This is not a bit of a clue, then please look at the next one! (^-^) V

A preliminary study on JavaScript function (vi)---closure

Related Article

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.