JS Closure (closure), personal understanding

Source: Internet
Author: User

First, closure concept understanding

Various professional literature on the JS "closure" (closure) definition is very abstract, thieves ugly understand. My understanding is that closures are functions that can read the internal variables of a function. Because only functions inside the function in the JavaScript language can read local variables, closures are simply understood as "functions defined inside a function". So, in essence, a closure is a bridge that connects the inside of the function to the outside of the function.

Second, the use

Closures can be used in many places. But it has two of its maximum usefulness, one of the variables mentioned earlier that can read inside a function, and the other is to keep the values of those variables in memory.

Third, the use of closures precautions

1, because the closure will make the variables in the function is stored in memory, memory consumption is very large, so can not abuse closures, otherwise it will cause the performance of the Web page.

2. The closure will change the value of the internal variables of the parent function outside the parent function and use it cautiously.

JS Closure (closure), personal understanding

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.