当前位置:网站首页>42.js -- precompiled
42.js -- precompiled
2022-07-28 02:58:00 【Like to drink pearl milk tea】
Tips : When the article is finished , Directories can be generated automatically , How to generate it, please refer to the help document on the right
1. Precompiling steps
js There are three steps to complete the explanation and execution :1. Syntax analysis ;2. precompile ( Global precompiling 、 Function precompile );3. Execute statement .
1. Syntax analysis
Symbol 、 Syntax check such as braces ;
2. Function precompile
Variable declaration promotion ,function Function declaration overall promotion ; It happens the moment before the function executes ( The actual process is as follows ):
(1) establish AO object --Activation Object( Execution context ):AO{ };
(2) Find parameter and variable declarations , Use variables and parameter names as AO Property name , That is, the variable promotion process , The value is undefined;
(3) Put the value of the argument into the formal parameter
(4) Find the function declaration in the function body , Value assignment function body
function fn(a) { console.log(a); var a=123; console.log(a); function a() {} console.log(a); var b = function() {} console.log(b); function d() {} } fn(1);(1) establish AO object --Activation Object( Execution context ):
AO{ };(2) Find parameter and variable declarations , Use variables and parameter names as AO Property name , That is, the variable promotion process , The value is undefined;
AO {
a:undefined,
b:undefined
}(3) Put the value of the argument into the formal parameter
AO {
a:1,
b:undefined
}(4) Find the function declaration in the function body , Values are assigned to the function body from (a Attribute in AO Object already exists , Therefore, only d attribute ):
AO {
a:1,
b:undefined,
d:
}
To ( Assign the function body to the attribute value ):
AO{
a:function a() {},
b:undefined,
d:function d() {}
}
2. When a function is called How to run the code ?
1. Analyze whether the code is correct Symbol Lexical analysis
var var=20; var 01js=100 var a; var a,2. Implicit operation ==> precompile : After the function call Before running the code
2.1 Each call of the function will generate an object : Execution time context object
2.2. to AO Object to add members : Local variables and formal parameter variables inside the function name As AO The property name of the object
AO:{a:undefined} ao.a=undefined ao.a=undefined// When formal parameters are the same as local variables No effect2.3. Assign the passed argument to AO Object properties
AO:{a:100}2.4. Local function declaration , assignment Let the name of the local function be AO Object has the same member name , Assign the function body to this attribute
//AO:{a:100,fn:function fn () {}} function fm(a) { console.log(a) var a=20 function fn () {} console.log(a) } var b=100 fm(b)3. Run code : The pre compiled ones are not running
//AO:{a:100==>20,fn:function fn () {}} console.log(a) //100 a=20 console.log(a) //20
3. Global precompiling
” overall situation “ That is, from inside the page js Of script Start tag to end tag , From off page js The first to last lines of the file .
The global precompiling process is roughly similar to the function precompiling process , It's just an invisible parameter in the overall situation 、 The concept of arguments .
1、 Generate a GO object --Global Object{},GO===window
2、 Variable Promotion
3、 Function enhancement// Examples of global precompiling : console.log(a) var a=123; function a(){} console.log(a)The pre compilation process of the program :
/*
1、GO{}
2、GO{
a:123
}
3、 perform
a. Print :function a(){}
b. GO{a:123}
c. Print :123*/
Examples of global precompiling :
console.log(a) var a = 20 function fn() { console.log(66) }Running results :
When the global scope runs code There is also precompiled ==> Global precompiling
Operation process :
1. Generate an object Global Object (GO)
GO:{}
2. Put all global variables Set to GO The property name
GO:{a:undefend}
3. Put all function names As GO Member name of , Assign the function body to this member
GO:{a:undefend,fn:function fn(){console.log(66)}}
4. Execute code
GO:{a:undefend==>20,fn:function fn(){console.log(66)}}
console.log(a) //undef
a = 20
Run in different environments js The code is different
GO All members of the object are shallow copied to the environment object window
node.js There is no such step in the environment
边栏推荐
- 一次跨域问题的记录
- Trivy [1] tool scanning application
- Arm32 for remote debugging
- Arm32进行远程调试
- Hardware standard
- 特征值和特征向量
- What "posture" does JD cloud have to promote industrial digitalization to climb to a "new level"?
- CNN训练循环重构——超参数测试 | PyTorch系列(二十八)
- How to simply realize the function of menu dragging and sorting
- [leetcode] 13. linked list cycle · circular linked list
猜你喜欢

Confusion matrix in CNN | pytorch series (XXIII)

RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑

CNN训练循环重构——超参数测试 | PyTorch系列(二十八)

POC simulation attack weapon - Introduction to nucleus (I)

基于FPGA的64位8级流水线加法器

入职华为od一个月的感受

JS event object 2 e.charcode character code e.keycode key code box moves up, down, left and right

Interpretation of cesium3dtilesets using customshader and examples of Omni effects

New infrastructure helps the transformation and development of intelligent road transportation

【stream】并行流与顺序流
随机推荐
【自我成长网站收集】
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
Opengauss source code, what ide tools are used to manage, edit and debug?
Actual case of ROS communication
One month's experience of joining Huawei OD
Design of edit memory path of edit box in Gui
CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
JS event object offsetx/y clientx y pagex y
Flutter God operation learning (full level introduction)
[wechat applet development (VI)] draw the circular progress bar of the music player
Data center construction (III): introduction to data center architecture
selenium+pytest+allure综合练习
Is it you who are not suitable for learning programming?
Collision and rebound of objects in unity (learning)
ROS的调试经验
Confusion matrix in CNN | pytorch series (XXIII)
Why is there no unified quotation for third-party testing fees of software products?
Docker高级篇-Docker容器内Redis集群配置
unity中物体碰撞反弹(学习)
Arm32进行远程调试
