As mentioned above, according to the standard, activity objects cannot be directly accessed. However, some specific implementations and
As mentioned above, according to the standard, activity objects cannot be directly accessed. However, some specific implementations do not fully comply with this provision. For example, in the implementation of SpiderMonkey and Rhino;, the function has a special attribute _ parent __, you can use this property to directly reference an activity object (or a global variable object) and create a function in this object.
For example (SpiderMonkey, Rhino ):
var global = this;var a = 10; function foo() {}alert(foo.__parent__); // global var VO = foo.__parent__; alert(VO.a); // 10alert(VO === global); // true
In the above example, we can see that the function foo is created in the global context, so the attribute _ parent _ points to the global context variable object, that is, the global object.
However, it is impossible to access the active object in the same way in SpiderMonkey: in different versions of SpiderMonkey, the _ parent _ of the internal function sometimes points to null and sometimes to global objects.
In Rhino, you can access activity objects in the same way.
For example (Rhino ):
Var global = this; var x = 10; (function foo () {var y = 20; // activity object var AO = (function () in the context of "foo () {}). _ parent __; print (AO. y ); // 20 // The _ parent _ of the current active object is an existing global object // The Special chain of the variable object is // so we call it the scope chain print (AO. _ parent _ = global); // true print (AO. _ parent __. x); // 10 })();Summary
In this article, we have learned in depth the objects related to the execution context. I hope this knowledge can help you solve some problems or confusions you have encountered. As planned, in subsequent chapters, we will explore the scope chain, identifier resolution, and closure.
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/1674.