JS Closed Package

Source: Internet
Author: User

1. Closures and anonymous functions are two different concepts

 Closures are functions that have access to variables within the scope of another function

2, create the form of closures:

Create another function inside a function

Understanding closures:

What happens to the function call procedure:

(1) When a function is called, an execution environment and the corresponding scope chain are created.

(2) Initializes the active object of the function with the values of arguments and other named parameters.

In the scope chain, the active object of the outer function is always second, and the outer function of the external functions of the active object is in third place .... , up to the global execution environment where the scope chain is focused

The above code first defines the compare () function and then calls it in the global scope. The call to Cpmpare () creates an active object that contains arguments, value1, and value2. Variable objects for the global execution environment (containing result, and compare) are second in the scope chain of the Compare () execution Environment

In the above example, the global activity object has: Compare, result, compare () Active objects are: value1, value2, arguments

JS Closed Package

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.