How the context is executed in JavaScript

Source: Internet
Author: User
Tags abstract define eval

Write in the front: always want to systematically summarize the knowledge of JavaScript, like the language also love the language. In the future want to engage in front-end work, in advance to comb their knowledge. The knowledge of the DOM was written earlier, and the level of awareness was limited. Not a few months to go to find work on the frontline, but they are still a rookie, specific writing when there is no complete thinking. After many considerations, the decision or translation of the classic series of foreign articles, summing up the promotion of the English level can also be a step, two-pronged, I believe that the future will certainly be good. Of course, this series of articles have been translated by a lot of people, the level is very high (I translated after the reference to some statements, thanks to predecessors). If you think my bad, also hope to pat the brick. Really can't see down, please bypass, heavy will hurt my young heart oh.

The English address of this series is posted here: http://dmitrysoshnikov.com/tag/ecma-262-3/

Introduction

This article will talk about the execution context of ECMAScript (translator Note: or execution Environment) and various types of executable code associated with this

The controller also enters an execution context whenever the controller jumps into the ECMAScript execution code.

Execution context (EC): ECMA-262 is used to define the typical and differential abstract concepts of a piece of executable code.

Standard documents do not accurately define the structure and type of the EC from a technical implementation perspective. This should be an issue that the ECMAScript engine considers when it comes to implementation.

Logically, a collection of dynamic execution contexts forms a stack, the bottom of which is generally the global execution context, the top-the current (active) execution context. Modify the stack by pressing in (push) and introducing (POP) various execution contexts.
Executable code

Executable code is a concept associated with the abstract concept of execution context, which, while talking about executable code, may also imply an execution context.

For example, we define an execution context stack as an array ecstack=[] whenever a function (even a recursive call function or a constructor) is entered, the stack is pressed into a new execution context, and the embedded eval function is the same.
Global Code

This code is executed at the "program level": for example, the externally loaded JS file or the local inline code (in <script></script> tag). The global code does not contain any code that exists in the body of the function. When initialized (the program starts), the Ecstack is as follows:

Ecstack=[globalcontext];

Function Code Snippet

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

When the function body (all functions) is entered, the new element is pressed into the ecstack stack. It is important to note that the specific function code does not contain its internal function code snippet. For example, we call a function that recursively calls itself:

(function foo (flag) {
    if (flag) {return
        ;
    }
    Foo (true);
}) (false)

The Ecstack stack is then amended as follows:

When the external Foo function is executed first
ecstack=[
<foo>functioncontext
Globalcontext]
//recursively executes the internal Foo function
ecstack=[
<foo>functioncontext-
<foo>functioncontext foo
Globalcontext]

When the function that exists in the current execution context returns, Ecstack pops up the corresponding execution context so that the continuous top-down execution and the stack pointer move continuously, which is a typical stack implementation. When the related segment code is finished, Ecstack only includes the global context, until the entire application finishes. An exception that is thrown but not intercepted also has one or more execution contexts.
Eval code

(Translator Note: A large number of senior academics have proposed not to use Eval as much as possible, and this part is not worth much.) Reduce the amount of reading, so do not translate)

This small part of the theory in the future further analysis of the implementation context of some of the details, such as variable objects, scope chain is very necessary. These theories will be mentioned in the relevant chapters.

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.