Pre-compiled (function expression & function declaration), typeof

JS run trilogy

  • Gramma analysis
  • Precompiled
  • Interpreted

Enhance the overall function declarations
variable declarations upgrade

Here Insert Picture Description

Precompiled prelude

Here Insert Picture Description
Here Insert Picture Description

Precompiled

  1. AO create objects
  2. Get parameter and variable declarations (including variable declarations inside an if statement), and the variable name as the parameter AO attribute name, value is undefined
  3. The parameter argument value and unified
  4. Find a function declaration in the function body, the value assigned to the function body

Step procedure as follows:

Here Insert Picture Description
3.
Here Insert Picture Description
4.

execution
Here Insert Picture Description
Here Insert Picture Description
added:
function expression: var a = function () { }
function declarations (lift): function a () {}

Here Insert Picture Description

Precompiled not only in the function body also occur in the global

Global:
1. objects GO generated} {GO
2. invisible parameter; only variable declaration undefined
X-invisible parameter argument unified 3.
4. The function declaration and the function imparting member

GO === window
Here Insert Picture Description
Example A:
Here Insert Picture Description
Here Insert Picture Description
execution
Here Insert Picture Description
Example B:
Here Insert Picture Description
Example C:
Here Insert Picture Description
Here Insert Picture Description
lifting Example D:
Here Insert Picture Description
lifting Example E:
Here Insert Picture Description

Supplementary typeof

Only one case (typeof) defined without error, returning undefined
Here Insert Picture Description
Example:
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/weixin_45179978/article/details/93209132