JavaScript's personal understanding of closures

Source: Internet
Author: User

As for closures, I understand that as a sub-function defined inside a function body function, the child function has a unique interface and exits. A variable that is a function body is referenced and the closure is activated when the function body returns.

About understanding we can combine the following code with the form of closures we see:

(function () {   //dosomething  }) ()

1. This sub-function can access variables, parameters, and other intrinsic functions (sub-functions) in the scope of the external function (function body) function.

2. When one of these intrinsics is called outside the outer function that contains them, a closure is formed.

Tips: The second parenthesis in a closed-form structure that indicates that a function is called to form a closure

3. So closures are also a bridge between the outside of the function and the inside of the function.

JavaScript's personal understanding of closures

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.