diff --git "a/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2022-10-31\351\242\204\347\274\226\350\257\221.md" "b/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2022-10-31\351\242\204\347\274\226\350\257\221.md" new file mode 100644 index 0000000000000000000000000000000000000000..63c508919195421335f28b5387753d3a368e88cc --- /dev/null +++ "b/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2022-10-31\351\242\204\347\274\226\350\257\221.md" @@ -0,0 +1,63 @@ +# 预编译 + +### 作用域 + +``` +var:如果在全局,块级 --> 全局变量 局部作用域(function)-->局部变量 + +let:不管在哪,都是局部 + +没有任何声明 a=5,不管在哪,都是全局 +``` + +**JS(单线程):** + +``` +**扫描全局:看有没有语法错误** + +**预编译(变量提升):** + +**1.创建一个AO(activation object)对象:临时存储容器** + +**2.往AO装形参,值赋为undefined AO={a:undefined, b:undefined}** + +**2.1找变量声明,值也赋为undefined AO={a:undefined, b:undefined,c:undefined}** + +**3.将形参与实参的值统一 AO=AO={a:1, b:2,c:undefined}** + +**4.找函数声明,值赋予函数体AO={a:f a(){}, b:2,c:f c(){}}** + +**执行一句,解释一句** +``` + +例子: function fn(a,b) { + +``` +console.log(a); + +function a(){} + +var a = 5; + +console.log(a); + +console.log(c); + +var c = 3; + +function c(){} + +console.log(c); + + } + + fn(1,2) +``` + +### GO AO + +GO:文件执行之前 + +AO:执行函数的前一刻 + +GO比AO先执行 \ No newline at end of file diff --git "a/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2122-11-02\351\227\255\345\214\205.md" "b/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2122-11-02\351\227\255\345\214\205.md" new file mode 100644 index 0000000000000000000000000000000000000000..fecca93a68b5da9f4684f98e35f6b5fd46fde639 --- /dev/null +++ "b/31\345\220\264\346\254\243\347\207\225/\347\254\224\350\256\260/2122-11-02\351\227\255\345\214\205.md" @@ -0,0 +1,31 @@ +作用域:存储了执行期的上下文集合 + +声明outer函数—>作用域链—>全局变量对象(GO) + +作用域链执行完会再产生AO,根据AO产生作用域链—>函数对象 + +执行完最里面的AO会自动最先销毁,再销毁GO + +闭包: + +返回函数可以调用 + +1.实现共用变量 + +2.做缓存 + +3.实现封装(继承) + +4.模块化开发 + +缺点:占内存 + +外层不能释放 + +没有调用就不会执行 + +立即执行函数:无需调用立即执行,执行完直接销毁 + +(function(a){} + +(b))b传入a中 \ No newline at end of file