Function scope and execution context

1, Category Code: Code and global functions (local codes)

  Compiled code is divided into (JS performed by the compiler) and execution stage (JS engine execution) stage. When the code is compiled, it will create the appropriate scope, when the code is executed, it creates the corresponding implementation

  Context.

2, Scope: is generated at compile time, and a set of access rules function identifier, determined by the location of the function declaration.

  Role: mainly used to isolate variables, different scope variable names can be the same

  Scope chain: forming a plurality of subordinate relationship scope chain, from the inside outward or from the bottom up. Find the rules defined variables

3, the execution context:

  1) Global execution context: the window before executing the global code execution context determined global, global data preprocessing.

    -Var variable declaration, add the window property

    Number -function statement, add window method

    -this assigned window

    - Before executing the global code

  2) The function execution context: before calling this function, perform the function thereof, a function to create a corresponding execution context of local data preprocessing

    - actual parameters assigned to the parameter is added to the execution context attribute

    -argument assignment argument, add function execution context property

    -Var variable declaration. Assignment underfined, add a function to perform context property

    -Function function declaration, add a method of execution context

    -this-> assignment calls the current function of the object

    - Before executing the function body

  Function execution context stack:

    - global code before execution, JS engine creates a stack to manage all stored execution context object

    - After the global execution context (window) is determined, which is added to the stack (push)

    - after the function execution context created, to add it to the stack (push)

    - In the current function is completed, remove the top of the stack of objects (pop)

    - When all the code executed, only the window stack  

Guess you like

Origin www.cnblogs.com/qqinhappyhappy/p/11612524.html