VariableObject is an abstract concept. It represents
The context of an execution can be abstracted as an object. Each execution context has a series of attributes (called context state) that are used to track the execution progress of associated code. This graph is a context structure.
Context Structure
In addition to the three required attributes (variable object), this pointer (this value), scope chain )), the execution context can also have any additional attributes based on the specific implementation. Next, let's take a closer look at these three attributes.
Variable Object)
A variable object is a scope of data related with the execution context.
It's a special object associated with the context and which stores variables and function declarations are being defined within the context.
Variable object is the scope of data related to the execution context ).
It is a special object associated with the context, used to store variables and function declarations defined in the context ).
Variable Object is an abstract concept. Different contexts use different objects. For example, in the global context, the variable object is also the global object itself [global object]. (This means that we can point to global variables through the Global Object Attributes ).
Let's take a look at the global execution context in the following example:
Var foo = 10; function bar () {}/// function declaration (function baz () {}); // function expression console. log (this. foo = foo, // true window. bar = bar // true); console. log (baz); // reference error. baz is not defined
The variable object (VO) in the global context has the following attributes:
Global variable object
As shown above, the function "baz" is not included in variable objects if it is used as a function expression. This is the reason why a ReferenceError occurs when a function tries to access the service. Note that, compared with other languages (such as C/C ++), ECMAScript only allows functions to create new scopes. Variables and internal functions defined in the function are not directly visible outside and do not pollute global objects. When using eval, we will also use a new (eval creation) Execution context. Eval uses the global variable object or the caller's variable object (the call source of eval ).
What is the function and its own variable object? In a function context, a variable object is represented as an activity object ).
Activation object)
When the function is activated by the caller, this special activity object is created. It contains common parameters and special parameters (arguments) objects (parameter ing tables with index attributes ). Activity objects are used as variable objects in the context of functions.
That is, the variable object of the function remains unchanged, but besides the stored variables and function declaration, it also contains the special object arguments. Consider the following:
Function foo (x, y) {var z = 30; function bar () {}// function declaration (function baz (){}); // function expression} foo (10, 20 );
Shows the next activation object (AO) in the context of the "foo" function:
Activation object
In the same way, function expressions are not in the ranks of AO.
Next we will talk about the third main object. As we all know, in ECMAScript, we will use the internal function [inner functions]. In these internal functions, we may reference its parent function variable or global variable. We turn these variable objects into the context scope object [scope object of the context]. Similar to the prototype chain [prototype chain] discussed above, we are called the scope chain [scope chain] Here.
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/1644.