当前位置:网站首页>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
边栏推荐
- Pychart shortcut key for quickly modifying all the same names on the whole page
- 为什么登录时,明明使用的是数据库里已经有的账号信息,但依旧显示“用户不存在”?
- JS event loop synchronous task, asynchronous task (micro task, macro task) problem analysis
- Cesium3Dtilesets 使用customShader的解读以及泛光效果示例
- 树的孩子兄弟表示法
- Is the interface that can be seen everywhere in the program really useful? Is it really right?
- Flutter神操作学习之(满级攻略)
- Arm32 for remote debugging
- [image hiding] digital image information hiding system based on DCT, DWT, LHA, LSB, including various attacks and performance parameters, with matlab code
- Arm32进行远程调试
猜你喜欢

A 64 bit 8-stage pipelined adder based on FPGA

Center-based 3D Object Detection and Tracking(基于中心的3D目标检测和跟踪 / CenterPoint)论文笔记

Building of APP automation environment (I)

【 图像去雾】基于暗通道和非均值滤波实现图像去雾附matlab代码

Using pytorch's tensorboard visual deep learning indicators | pytorch series (25)

一次跨域问题的记录

Flutter God operation learning (full level introduction)

分布式 session 的4个解决方案,你觉得哪个最好?

@The function of valid (cascade verification) and the explanation of common constraint annotations
![[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code](/img/50/f063cec7610015a062e3773d9916cd.png)
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code
随机推荐
[acnoi2022] one step short
2022.7.8 eth price analysis
Job 7.27 IO process
Pycharm 快速给整页全部相同名称修改的快捷键
Redis AOF log persistence
CSDN Top1 "how does a Virgo procedural ape" become a blogger with millions of fans through writing?
小程序已获取数据库合集中的总记录、用户位置,怎么用Aggregate.geoNear将经纬度由近到远排列?
数据湖:海量日志采集引擎Flume
P6118 [JOI 2019 Final]珍しい都市 题解
[ACNOI2022]总差一步
Representation of children and brothers of trees
[wechat applet development (V)] the interface is intelligently configured according to the official version of the experience version of the development version
一次跨域问题的记录
Trivy [1] tool scanning application
Welcome to CSDN markdown editor Assad
【TA-霜狼_may-《百人计划》】图形3.5 Early-z 和 Z-prepass
JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
分布式 session 的4个解决方案,你觉得哪个最好?
【红队】ATT&CK - 文件隐藏
