Understand the process of dialogue on the scope js

First of all, the members of this dialogue are:

  • engine

   Responsible for compilation and execution of the entire program Javascript

  • translater

   Responsible for parsing and code generation

  • Scope

   Responsible for collecting and maintaining all series of queries a statement identifiers, and to develop a set of very strict rules that determine the code currently executing access to these identifiers


Dialogue with var a = 2; exemplified

  1. Encountered var a, the compiler will ask whether there is scope a variable name exists in the collection of the same scope. If so, the compiler ignores the statement and continue to be compiled. Otherwise will ask the current scope the scope of the collection declare a new variable, and named a;
  2. Next, the compiler will generate code that requires runtime engine, the code a = 2 is used to process the copy operation (compiler to compile the code into the engine know) Next, when the engine is running will also ask scope Is there a variable, and if so, engine directly use this variable can be executed otherwise will continue to look for the variable.

   If the engine finally found a variable, it will be 2 assigned to him. Otherwise, the engine will raise their hands and throws an exception

   [Note:] The compiler will be declared only execution engine

 

Guess you like

Origin www.cnblogs.com/evilr/p/11526392.html