The scope of JS is a relatively complicated thing
The scope of JS is static. When a function is defined, the scope of the function is the scope in which the function is defined, not the scope in which the function is called. domain.
When a function is called, a new scope will be created. The variables defined with var in this scope are local variables. Generally, the scope created by this call after the function execution is completed. will be recycled by the system.
When the function trap is defined, if the function defined inside is saved (for example: assigned to a global variable). Then the scope in which it is located (the scope created when calling the external function) must also be saved together (that is to say, when the execution of the external function ends, the scope created during this call will not be recycled by the system, and it will have to wait until the saved When the function is recycled by the system, it is recycled by the system together).
Scope Saved All local variables in this scope are of course also saved.