What scope is?

  1. Compiler theory
    1. Word / lexical analyzer tokenizing / lexing
      1. Code string decomposition, as var a = 2;will be decomposed to var, a, =, 2, ;. Each individual element to the lexical unit (token).
      2. Spaces whether as a lexical unit, to see whether it makes sense spaces.
      3. Lexical unit generator determines whether a part of other lexical units, called a stateful parsing rule, this process is the lexical analysis. If you are stateless, that word.
    2. Parsing / syntax analysis
      1. This method elementary stream (array) is converted into an abstract syntax tree. As shown below
    3. Code Generation
      1. The AST is converted to executable code process.
        1. About to write code that translated into a set of machine instructions, create variables, memory allocation, and the value stored therein.
    4. For var a
  2. Understand the scope of
    1. engine
      1. Compile and execute programs
    2. translater
      1. Parsing and code generation
    3. Scope
      1. Collect and maintain a list of all identifiers of inquiry to determine the code currently executing access to these identifiers
    4. Assignment of variables
      1. The compiler to declare a variable in the current scope (if not previously declared); engine to find the variable scope is running, can be found on its assignment
  3. LHS and RHS
    1. Variable on the left side of an assignment, a LHS inquiry; the right RHS
    2. RHS query is to find the value of a variable, LHS inquiry is to find a variable container, so you can assign it a value
      1. console.log(a); // RHS To find the value of a
      2. a = 2; //LHS Find a target (container) this assignment is = 2
      3. ```js
        function foo(a) {
        console.log( a ); // 2
        }
      foo(2);
    1. The last line foo (..) call, RHS quote, because to find the value of foo
    2. When the parameter passing, a = 2 implicit operations, the LHS query, lookup vessel 2 =
    3. console.log (a) the value of a query RHS
    4. If the console.log () may receive parameters, the 2 (RHS above to find the value of a query) assigned to arg1, parameter 1 is LHS.
      `` `

    5. LHS is a function declaration or RHS?

  4. Nested scopes
    1. A scope is used to determine where and how to find the rule identifier.
  5. why lhs & rhs?
    1. For undeclared variables
    2. 23
    3. If it is LHS, shall be assigned container
      1. If strict mode, ReferenceError
      2. If a non-strict mode automatically creates a variable (global scope), returned to the engine.
    4. If it is RHS, can not find the value, ReferenceError
  6. Exercise
    1. Where the right identifier (not a number, including function identifier and a different binary representations of numbers). RHS should be carried out

Guess you like

Origin www.cnblogs.com/wydumn/p/11575488.html