first quote original
in-depth understanding of the JavaScript series (11): execution context (Execution Contexts)
Theeval code is a little interesting. It has a concept: calling context (calling context), for example, the context generated when the eval function is called. The eval (variable or function declaration) activity affects the calling context (calling context).
eval("var x = 10");
(function foo() {
eval("var y = 20");
})();
alert(x); // 10
alert(y); // "y"
ECStack:
ECStack = [
globalContext
];
// eval("var x = 10");
ECStack.push(
evalContext,
callingContext: globalContext
);
// eval exited context
ECStack.pop();
// foo funciton call
ECStack.push(<foo> functionContext);
// eval("var y = 20");
ECStack.push(
evalContext,
callingContext: <foo> functionContext
);
// return from eval
ECStack.pop();
// return from foo
ECStack.pop();
< hr >
take eval ("var x = 10");
as an example, when the controller enters the Eval function, it will give ECStack push two elements: evalContext, callingContext:globalContext,
there are three elements in the ECStack at this time,
ECStack = [globalContext, evalContext, CallingContext:globalContext]
my question is:
/ / eval exited context
ECStack.pop ();
will one CallingContext:globalContext, pop up or two CallingContext:globalContext,evalContext elements pop up in this step?
I think two elements should pop up, but I remember pop can only manipulate one element, so evalContext will remain in ECStack.