Execution context of javascript Series

Source: Internet
Author: User

Preface: I want to systematically summarize the javascript knowledge I have learned. I like this language and love it. In the future, I want to work on the frontend, and sort out my knowledge in advance. I have written some DOM knowledge before, and the level of perception is limited. In less than a few months, I had to go to the front line to find a job, but I was a newbie. I didn't have a complete idea yet. After many considerations, I decided to translate the classic series of articles from other countries. At the same time, I can take a further step in improving the English proficiency. I believe it will be good for the future. Of course, many people have already translated this series of articles, and the level is quite high (I have translated some of the statements, and I would like to thank my predecessors ). If you think that I am a bad guy, you may want to pat the bricks. I can't see it anymore. Please make a detour. It will hurt my young soul. Introduction This article will talk about the execution context of ECMAScript (Translator's note: or execution environment) and various types of executable code related to this. Whenever the Controller redirects to the Execution Code of ECMAScript, the Controller enters an execution context. Execution context (EC): an abstract concept used by ECMA-262 to define the typicality and difference of a piece of executable code. The standard documentation does not accurately define the EC structure and type from the technical implementation perspective. This should be an issue for the ECMAScript engine in its specific implementation. Logically, a set of dynamic execution contexts forms a stack. The bottom of the stack is generally the global execution context, and the top is the current (active) Execution context. Modify the stack by pushing and publishing various execution context. executable code is a concept associated with the abstract concept of execution context. When talking about executable code, it may also mean an execution context. For example, we define an execution context stack as an array ECStack = []. Every time a function is entered (even a function called recursively or constructor), this stack is pushed into a new execution context, the same is true for Embedded eval functions. Global code is executed in the "program layer", for example, externally loaded js files or local Inline code (in the <script> </script> label ). The Global Code does not contain any code that exists in the function. During initialization (the program starts), The ECStack is as follows: 1 ECStack = [globalContext]; when the function code segment enters the function body (all functions), The ECStack has a new element in the medium pressure. Note that the specific function code does not contain its internal function code segment. For example, we call a function that recursively calls itself: Copy code 1 (function foo (flag) {2 if (flag) {3 return; 4} 5 foo (true ); 6}) (false) copy the code and then modify the ECStack stack as follows: copy code 1 // when the external foo function is executed first 2 ECStack = [3 <foo> functionContext4 globalContext] 5 // when the internal foo function is recursively executed 6 ECStack = [7 <foo> functionContext -recursive foo8 <foo> functionContext9 globalContext]: copy the code. When the function that exists in the current execution context returns, ECStack pops up the corresponding execution context, so that the stack pointer is constantly moving from top to bottom for continuous execution. This is a typical stack implementation method. After the relevant code segment is executed, ECStack only includes the global context until the entire application ends. One thrown but not intercepted exception also has one or more execution contexts. Eval code. This small part of the theory further analyzes details related to the execution context in the future, such as variable objects and scope chains. These theories will be mentioned in relevant chapters.

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.