A. Ecstack
The execution context is a stack, and each time the function is entered, the function context is pressed into the stack and the function context is ejected from the ecstack when the function exits.
two. Global Contexts
When the program is initialized, it is pressed into the ecstacks, for example:
Ecstack = [ globalcontext];
three. Function Code
When execution enters function, Ecstack will push into a new item, noting that the new item does not contain funtion inside the function.
(function foo (flag) { if (flag) { return; } Foo (true);}) (false);
When Foo is executed recursively, the status of Ecstack behaves as follows:
// First activation of Foo Ecstack = [ <foo> functioncontext globalcontext]; // recursive activation of foo Ecstack = [ <foo> functioncontext–recursively <foo> functioncontext Globalcontext];
Throwing an exception that is not caught will result in the exit from one or more context.
Four. Eval Code
The variables and functions that are defined by eval affect the context in which the eval is invoked, for example:
// Influence Global Contexteval (' var x = Ten '); (function foo () { // and here , variable ' y ' is // Created in the local context // of "foo" function eval (' var y = + ');}) (); // Ten // "Y" is not defined
Ecstack =[Globalcontext]; //eval (' var x = Ten ');Ecstack.push ({context:evalcontext, callingcontext:globalcontext});//Eval exited contextEcstack.pop ();//foo Funciton callEcstack.push (<foo>functioncontext); //eval (' var y = x ');Ecstack.push ({context:evalcontext, Callingcontext:<foo>Functioncontext}); //return from EvalEcstack.pop ();//return from FooEcstack.pop ();
JavaScript Learning-Execution context (execution contexts)