Js variable object scope chain, js variable object
Executable code: Global, function, eval
Context type created during code execution: global context, function context, and eval Context
Execution context (EC) attributes: Variable object (vo), this, scope chain (SC)
Execution context Stack
Variable object
Used for storage: variables, declarative functions, and parameters
Var a = 10; delate // window. a cannot be deleted; delate // window. a can be deleted
Code execution steps:
- Enter Context
- Initialize this scope chain variable object
- Variable instantiation
- Code Execution
Scope chain
The scope chain can be seen as an array.
- Scope chain of global context [Global Object]
- Function context scope chain [currently activated object + function. [[scope]
With can temporarily change the scope chain, because more than once the variable is searched, may lead to lower efficiency.
Use an example to describe the Code Execution Process
EC: Execution Context
VO: variable objec variable object
SC: scope chain
AO: activation object
var y = 10;function test(){ var y = 2; return function(){ alert(y); }}var fun = test();fun();
End