当前位置:网站首页>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
边栏推荐
- [self growth website collection]
- 特征值和特征向量
- Canonical Address
- 初识C语言 -- 操作符和关键字,#define,指针
- Cesium3Dtilesets 使用customShader的解读以及泛光效果示例
- 【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码
- First knowledge of C language -- structure, branch and loop statements
- A brief analysis of the differences between functional testing and non functional testing, recommended by Shanghai haokoubei software testing company
- Day 19 of leetcode
- Redis AOF log persistence
猜你喜欢
![[wechat applet development (VI)] draw the circular progress bar of the music player](/img/eb/9ce5d196970a6d6a887bf3e1d742ee.png)
[wechat applet development (VI)] draw the circular progress bar of the music player

JS event loop synchronous task, asynchronous task (micro task, macro task) problem analysis

On the problem that sqli labs single quotation marks do not report errors

【图像隐藏】基于DCT、DWT、LHA、LSB的数字图像信息隐藏系统含各类攻击和性能参数附matlab代码

【微信小程序开发(六)】绘制音乐播放器环形进度条

Confusion matrix in CNN | pytorch series (XXIII)

How do you use the jar package sent by others (how to use the jar package sent by others)

【信号去噪】基于卡尔曼滤波实现信号去噪附matlab代码

别人发你的jar包你如何使用(如何使用别人发您的jar包)

Pytest the best testing framework
随机推荐
@Valid的作用(级联校验)以及常用约束注解的解释说明
vscode debug显示多列数据
Day 8 of DL
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
别再用 offset 和 limit 分页了,性能太差!
【微信小程序开发(五)】接口按照根据开发版体验版正式版智能配置
Selenium+pytest+allure comprehensive exercise
clientY vs pageY
【红队】ATT&CK - 文件隐藏
selenium+pytest+allure综合练习
【OpenGL】GLES20.glClear
trivy【1】工具扫描运用
Arm32进行远程调试
1313_ Pyserial installation and document generation
注意,这些地区不能参加7月NPDP考试
社恐适合什么工作?能做自媒体吗?
RTSP/Onvif协议EasyNVR视频平台一键升级方案的开发设计逻辑
Why is there no unified quotation for third-party testing fees of software products?
Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记
[acnoi2022] one step short
