Data in the execution context (variables, function declarations, and function parameters) are stored as attributes in the variable object. Variable
Data in the execution context (variables, function declarations, and function parameters) are stored as attributes in the variable object. The variable object is created every time it enters the context and is filled with the initial value. The value is updated in the code execution phase.
This chapter focuses on more details that are directly related to the execution context. This time we will mention an issue-the scope chain.
If you want to briefly describe and display the focus, most of the scope chains are related to internal functions.
We know that ECMAScript allows the creation of internal functions, and we can even return these functions from the parent function.
var x = 10; function foo() { var y = 20; function bar() { alert(x + y); } return bar; } foo()(); // 30
In this way, it is obvious that each context has its own variable object: for a global context, it is the global object itself; for a function, it is the activity object.
The scope chain is the list of all variable objects (including parent variable objects) in the internal context. This link is used for variable query. In the preceding example, the scope chains of bar context include AO (bar), AO (foo), and VO (global ).
However, let's take a closer look at this issue.
Let's start with the definition and further discuss the example.
The scope chain is related to an execution context. The variable object chain is used for Variable Search in identifier parsing.
The scope chain of the function context is created when a function is called, including the activity object and the [[scope] attribute inside the function. Next we will discuss in more detail the [[scope] attribute of a function.
The following is a diagram in the context:
ActiveExecutionContext = {VO :{...}, // or AO this: thisValue, Scope: [// Scope chain // list of all variable objects // for identifiers lookup]};
Its scope is defined as follows:
Scope = AO + [[Scope]]
This association and identifier parsing process will be discussed below, which is related to the function lifecycle.
Additional reading
The topic list of this article is as follows:
- How should we understand the working principle of the JavaScript engine?
- JavaScript exploration: the importance of writing maintainable code
- JavaScript exploration: exercise caution when using global variables
- JavaScript exploration: var pre-parsing and side effects
- JavaScript exploration: for Loop (for Loops)
- JavaScript exploration: for-in loop (for-in Loops)
- Exploring JavaScript: Prototypes is too powerful
- JavaScript: eval () is the devil"
- JavaScript exploration: Using parseInt () for Numerical Conversion
- Exploring JavaScript: Basic coding specifications
- JavaScript exploration: function declaration and function expression
- JavaScript exploration: Name function expressions
- JavaScript: function name in the debugger
- JavaScript: JScript Bug
- JavaScript exploration: Memory Management of JScript
- Exploring JavaScript: SpiderMonkey's quirks
- JavaScript exploration: an alternative solution to naming function expressions
- JavaScript exploration: Object
- JavaScript exploration: Prototype chain
- JavaScript exploration: Constructor
- JavaScript probing: executable context Stack
- Execution context 1: Variable object and activity object
- Execution context 2: Scope chain Scope Chains
- Execution context 3: Closure Closures
- Execution context 4: This pointer
- Exploring JavaScript: Powerful prototype and prototype chain
- JavaScript Functions 1: function declaration
- JavaScript function 2: function expressions
- JavaScript function 3: function expressions in a group
- JavaScript function 4: function Constructor
- JavaScript variable object 1: VO Declaration
- JavaScript variable object 2: VO in different execution contexts
- JavaScript variable object 3: two stages of execution Context
- JavaScript variable object IV: Variables
- Property of the JavaScript variable object __parent _
- JavaScript scope chain 1: Scope chain Definition
- JavaScript scope chain 2: function Lifecycle
- JavaScript scope chain 3: Scope chain features
- JavaScript closure 1: Introduction to closures
- JavaScript closure 2: Implementation of closure
- JavaScript closure 3: Closure usage
This article is available at http://www.nowamagic.net/librarys/veda/detail/1675.