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: