There are three kinds of code-running environments in javascript:
- Global Code
- Default environment for JavaScript code to start running
- Function Code
- Code into a JavaScript function
- Eval Code
- Executing code using eval ()
In order to represent a different runtime environment, JavaScript has a concept of an execution context (execution Context,ec) . That is, when the JavaScript code executes, it enters a different execution context, which forms an execution context stack (execution context stack,ecs).
For each execution context there are three important attributes, the variable object (Variable object,vo), the scope chain (scope chain), and this.
Variable objects are data scopes that are related to the execution context. It is a special context-sensitive object that stores the variables and function declarations defined in the context. In other words, the following information is included in the general VO:
- Variable (var, Variable Declaration);
- function declaration (Functions Declaration, FD);
- Formal parameters of a function
- function expression (relative to function declaration) not included in Vo
- There are no variables declared with VAR (this variable is a "global" way of declaring, just adding a property to global, not in VO)
The activation object is created at the moment of entry into the function context, and it is initialized by the arguments property of the function.
- Callee: Reference to the current function
- Length: The number of parameters that are actually passed
- Properties-indexes: is the parameter value of the function (sorted from left to right by argument list)
Execution context for JavaScript