Understanding of JS closures

Source: Internet
Author: User
First, we should explain the characteristics of the closure, so we should better understand the two features of the closure: 1. As a reference to a function variable-when the function returns, it is in the active state. 2. A closure is a stack that does not release resources when a function returns. In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated,

First, we should explain the characteristics of the closure, so we should better understand the two features of the closure: 1. As a reference to a function variable-when the function returns, it is in the active state. 2. A closure is a stack that does not release resources when a function returns. In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated,

We should first explain the characteristics of the closure to better understand it.

Closure has two features:

1. As a reference to a function variable-when a function is returned, it is activated.
2. A closure is a stack that does not release resources when a function returns.

In fact, the above two points can be merged, that is, when the closure function returns, the internal variables of the function are activated, and the stack zone of the function is retained.


Original address: Stupid bird flying technology sharing website http://www.sucker-fly.com/archives/519 <无>
function a(){ var i=0; function b(){ alert(++i); } return b; } var c = a(); c(); 
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.