Understand javascript_15_scope allocation and variable access rules, and then send a closure _ javascript Technique

Source: Internet
Author: User
Before reading this blog post, please read "Understanding the Javascript_13 _ execution model details" and explain the issue about scope allocation in the execution model details, this blog post will detail the relationship between function objects, scope chains, and execution context. Scope allocation and variable access rules
In ECMAScript, functions are also objects. Function objects are created based on the Function declaration during variable instantiation, or when a Function expression is calculated or a Function constructor is called. (For 'function object', see Understanding Javascript_08 _ function objects.) Each function object has an internal [scope] attribute, which is also composed of an object list (chain. The internal [scope] attribute references the scope chain for creating their execution environment. At the same time, the active objects in the current execution environment are added to the top of the Object List. When we access variables within a function, it is actually the process of searching for variables on the scope chain.

The theory is too strong (I am in summary !), Let's take a look at the Code:

The Code is as follows:


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.