Js static scope function.

Source: Internet
Author: User

JS scope is a complicated thing.

The JS scope is static. when defining a function, the function scope defines the scope of the function, rather than the scope of the function.

When a function is called, a new scope is created. The variable defined by var in this scope is a local variable, generally, after the function is executed, the created scope will be recycled by the system.

When defining a function trap, if the function defined in it is saved (for example, assigned to a global variable ). Then, the scope of the function (the scope created when the external function is called) must be saved together (that is, the scope created during the call at the end of the external function execution will not be recycled by the system, wait until the stored function is recycled by the system ).
All local variables stored in the scope are also saved.

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.