Execution context Stack
There are three types of ECMAScript code: Global Code, function code, and eval code. The code executes in its execution context.
There is a unique global context, and there may be multiple functions and the eval context. Each function call goes to the execution of the function
Below, the code that executes the function. When called to the Eval function, enter into the eval execution context and execute its code.
Notice that a function may produce a finite set of contexts, because each call to a function (or even its own invocation) produces a
New context, accompanied by a new context state:
function Foo (bar) {} // call the same function // generates three different contexts, each time it is called // at the same time by the different upper and lower states (bar parameter value is different)foo (ten); foo (30);
A context can be used to activate another context called the caller. A context is being activated called the callee. Be adjusted
At the same time, the user may become the caller of another callee (for example, a function is called by the global context and it
Called an intrinsic function).
When a caller activates (invokes) the callee, the caller suspends its context and transfers the control flow to the
Called by the caller. The callee is pushed into the stack and becomes the executing context. After the callee finishes, it transfers the control
To the callee, then executes the callee context procedure (it may activate another context) until it ends, and so on.
The callee may simply return or exit unexpectedly. Throws an exception without capturing one or more upper and lower possible exits (removing the stack)
Text
When all the ECMAScript programs run, the execution stack, such as the top of the stack, is the current execution context:
When the program starts executing, it goes into the global execution context, which is at the bottom of the stack and the first element of the stack.
In addition, the global code is initialized to create the necessary objects and functions. When executed in the global context, its code may be activated
(already created) function, this function will go into their execution context, press the new element onto the stack, and in turn the class
Push. After this initialization is completed, the running system waits for certain events (for example, a user's click) to activate
function, and enters into a new execution context.
In the diagram below, there is a function context called EC1, and global EC, which we have the following process stack modifications
EC1 of the stack and the stack
This is a clear explanation of how the ECMAScript system manages the code of execution when it is run.
More information about the execution context in the next section, the execution context.
As we said, each execution context may be similar to an object in the stack. Let's look at its structure and what kind of state (which
Properties) A context is required to execute its code.
JavaScript's execution context stack