Precompiled & scope chain

Argument difference between Form:

 

fun (a, b) is the parameter of the open space is used

fun (5,10) is passed to the argument values of a and b

Equivalent function inside creates two variables and assignments

 

 

1. The variable parameter: This is called only when the allocated memory space, at the end of free space; thus parameter is valid only within the function.

2. arguments: may be variables, constants, expressions, functions, and so on; whether the argument is an amount of what type of, during function calls, they must have a value determined in advance with the assignment should therefore enter other methods argument that the obtained determination value.

 

JavaScript runs trilogy

1. Syntax Analysis: Syntax Error not proceed back operation, and vice versa for back operation;

2. precompiled: Before the statement is executed, it will be pre-compiled;

3. interpreted: execute the statement after the compilation is over;

 

 Step 4 precompiled

AO objects 1. Create a local (function), create global objects GO time.

2. Get parameter and variable declaration, the variable name as the parameter name and attribute name AO, GO initial value of the object or attribute name is undefined.

3. The parameter argument values ​​passed unified

4 .. find the function declaration inside the body of the function, the function value to the body

The Code ......

 

1. First, the global execution context object is created GO
      GO {
      2. statement on the parameter and variables, as a property name, value is undefined
        Global: undefined - after performing -> 100
      3 no parameters for global object
      4. In the function body to find the function declaration, given the value of the function body
        Fn: Fn function () {};
    }
    performing global
    1. global = 100
    2.fn (); (precompiled first Fn (), re-execute)


    (AO function precompiler generates see below)


    {AO
    2. Statement of parameter variables and, as a property name, value is undefined
  // when present in the local variable AO AO first find a local variable in the variable, though this time the global presence of global GO 100, However, there are already local to global undefined
      global: AO undefined --fn to perform the second sentence -> AO 200 --fn performed to the fourth sentence -> 300
      3 no parameter
      4. no function declaration
    }
    Fn ()
    A0 {performed
      of one: console.log (global); // undefined performed on line AO global: undefined;
      the second sentence: global = 200;
      the third sentence: console.log (global); / / find in the AO 200 has become a global
      fourth sentence: global = 300; 
    }

    so finally we
    the GO {
      global: 100
      Fn: Fn function () {};
     }
    AO {
    global: 300
    }

 

 

Scope chain: set of execution context object [scope] stored in this collection is called the scope chain

Function is a target in some of our properties (name, prototype) that can be accessed not have access to the [scope] property

[scope]属性:是指作用域,储存了运行期的上下文(AO和GO)集合

 

 

 

 图二

在b定义的时候a马上快执行完的时候的图像

首先b会继承了aAO和GO,这里的aAO全等于a中的aAO

在b自己执行的时候会变成(图二)

scope chain中的数值代表数值的key,key代表:

0 ---自己的AO(Activation Object)

1---b的AO

2---GO(Clobal Object)

 

Guess you like

Origin www.cnblogs.com/yang1997/p/11838460.html