1. The scope chain of JavaScript functions is defined as the scope chain and the run-time scope chain;
2. When the function is defined, it has an attribute [[scope]] that identifies its defined scope chain, and defines the scope chain [[scope]] to comply with the rule that the scope chain [[scope]] is always the scope chain of the execution of the external function where the function is defined;
3. The definition scope chain of global functions contains only the properties of Windows;
4. When a function is executed, the scope chain always presses the head of the scope chain into the current active object (it contains this,arguments, parameters, local variables) when defined;
5. When the function executes, the variable addressing is always looked down from the top of the scope chain, so the global variable is addressed at the slowest rate;
6. When the internal function is executed, he still has access to its complete scope chain. This is why closures can be accessed at run time by variables that have been defined by external functions that have been terminated;
7. When a function execution encounters a with statement, it temporarily presses all the properties of the specified object at the top of the scope chain as the top of the scope chain;
8. When a function execution encounters a catch, it temporarily presses the catch-specified Error object at the top of the scope chain as the topmost of the scope chain;
Here's an example and plot the scope chain to deepen the understanding:
There is this piece of code:
Copy Code code as follows:
function assignevents () {
var id = "xdi9592";
document.getElementById ("Save-btn"). onclick = function (event) {
SaveDocument (ID);
};
}
The anonymous closure generated by this function is called closure, and the scope chain is plotted when the following diagram defines the scope chain and closure for assignevent execution: