# Execution Context #
* * Definition: When executing a function, it produces a context object that holds variables, function declarations, and this.
* * * function: Used to save the data required for this run time
When an execution context (execution context) is generated, the browser does the following three preparations:
1. Extract the var declared variable and assign the value to undefined
2. Extract the declarative function.
3. Assign this value to the window or to the current object.
Each time a function executes, it produces an execution context,
Because the function parameters are different, there are different calculation results.
# # Global Context Environment # #
Global-level code, such as multiple script tags, that go into the global execution context once executed
1. Extract common variables, such as Var A, and assign a = undefined
2. Extract the declarative function, function fn () {}
3. Assign this value, this point to the window
# # Local Context Environment # #
Generated at the time of the function call, each invocation is generated, and the call is completed and destroyed (except for the closure).
1. Extract common variables, such as Var A, and assign a = undefined
2. Extract the declarative function, function fn () {}
3. Assign this value, this point to the current object
4. Assigning values to parameters
5. Assigning Values to arguments
6. Value scope of free variables, find and assign values
Free variables: Variables that are not declared in the current scope will be searched up to the previous level until the window
Arguments: is a copy of the argument, consistent with the argument.
# # execution Context Stack # #
* * Press stack and out stack * *
Stack: The function is not called when only the global context is executing, each call to the function will produce a local context, which is the stack, that is, into the stack.
Stack: After the function call is completed, it will be out of the stack, destroying the local context of the call
Note: If a function is nested inside a multi-layered function, there will also be nesting of multiple execution contexts
Stacking and stacking are also generated by nesting
Execution context-javascript Object-oriented advanced