JavaScript---Closures

Source: Internet
Author: User

Everything here is written to yourself!

1. Understanding of closures.

Closures are a means by which local variables within a function can be manipulated outside the function.

2. Cases.

Gets and sets the local variables inside the function functions. (normal condition gets less than n)

Click the number of the Li output li.

Every call is different.

    

     

3. Precautions for using closures.

1). Closures can cause variables inside the function to be stored in memory and have a large memory consumption, so closures cannot be abused, which can cause Web page performance problems. Memory leaks may be caused in IE. try to remove unused local variables before exiting the function.

2). Closures can change the values inside the function outside of the function, and when the parent function is used as an object, the closure is used as a public method and the local variable as a private property, the value of the local variable is not easily changed.

JavaScript---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.