1. Each JavaScript function is an instance of a Function object. It has an internal property [[Scope]] that is only accessible to the JavaScript engine. This [[Scope]] stores a scoped collection, which is called a "scope chain", and the collection stores "mutable object" VO or "active object" AO (AO has more this and arguments properties than VO).
2. When a function is created, all mutable objects in the scope chain of its parent scope will be added to its [[scope]] (if the parent scope is global, then only one global object will be added to the scope chain of the current function).
3. When a function is executed, the execution environment of the function will be pushed into an environment stack:
1. At this time, the variable initialization stage of the function enters. This stage determines the internal function: this value, function parameters, function declarations, variable declarations, and arguments. Based on these values, the active object AO of the current function will be composed, and the AO object will be saved to the first position of the current function scope chain.
Note: AO is filled in the following order:
1. Function parameters (if there is a parameter passed, it will be assigned. If the parameter is not passed, the initialization value is undefined) The second priority is
2. Function declaration (if a life name conflict occurs, it will be overridden) The highest priority is
3. Variable declaration (the initialization variable value is undefined, if a life name conflict occurs, it will be ignored) Priority third
2. Then it is the execution stage of the function. All variables and function declarations used in the current function will be searched from the [[Scope]] scope chain of the current function. According to the location of the object in the scope chain, the AO object of the current function will be first searched. If there is no upper object, the global object will be found. If there is no, an error will be reported (the variable is not defined).
The above JavaScript function execution process is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.