JavaScript Learning-Execution context (execution contexts)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.