*/
// 预编译发生在执行之前
// 1.初始化全局对象
// Global Object 全局对象
// 2.全局作用域下 函数声明提升
/*
Global Object {}
function foo: undefined
// 3.全局作用下 变量声明提升
/*
Global Object {
function foo: undefined,
a: undefined,
b: undefined,
c: undefined,
}
*/
// 4.给提升的函数赋值 function
/*
Global Object {
function foo: function,
a: undefined,
b: undefined,
c: undefined,
}
*/
// --- Go 预编译结束 ---
// --- 解析执行 ---
// 给Global Object 对象下属性 重新赋值的过程
// var a = '123'; // 执行完毕后go 什么变化?
/*
Global Object {
function foo: function,
a: '123',
b: undefined,
c: undefined,
}
*/
// var b = 'xk';
/*
Global Object {
function foo: function,
a: '123',
b: 'xk',
c: undefined,
}
*/
// var c = function(){}; // 声明变量c 赋值为函数指针
/*
Global Object {
function foo: function,
a: '123',
b: 'xk',
c: function,
}
*/
// ---Go 这段 重新赋值结束
// --- 函数定义阶段 没执行
// function foo(a,b){
// 函数执行前准备
// 1.初始化Active Object (AO) 对象
/*
Active Object{}
*/
// 2.提升形参
/*
Active Object{
a:undefined
b:undefined
}
*/
// 3.提升函数
/*
Active Object{
a:undefined
b:undefined
bar:undefined
}
*/
// 4.提升变量
/*
Active Object{
a:undefined
b:undefined
bar:undefined
lt:undefined
}
*/
// 5.给提升的函数赋值 function
/*
Active Object{
a:undefined
b:undefined
bar:function
lt:undefined
}
*/
// 6.形参实参相统一
/*
Active Object{
a:1
b:2
bar:ufunction
lt:undefined
}
*/
// --- AO预编译结束 ---
// --- 解析执行 ---
// var lt = 'lt';
// /*
// Active Object{
// a:1
// b:2
// bar:function
// lt:'lt' undedined--->'lt'
// }
// */
// function bar(){}1
// } // 执行完毕 AO 销毁
// foo(1,2)
// var x = 20;
// var a = {
// x: 15,
// fn: function () {
// var x = 30;
// console.log(this);
// return function () {
// return this.x
// }
// }
// }
// // console.log(a.fn(); //
// // a.fn();
// // function f1() {
// // return this.x
// // }
// // console.log(k);
// // (a.fn())();
// console.log((a.fn())()); //
// // console.log(a.fn()());
// // console.log(a.fn()() == (a.fn())());
// // function f2(){};
// // f1()
// function test() {
// console.log(this === global); // true
// }
// test() //
// console.log(window);
// const obj = 1
// function test() {
// console.log(this);
// }
// const testObj = test.bind(obj);
// // test(); //
// // testObj(); //
// testObj();
预编译过程
最新推荐文章于 2023-10-20 07:00:00 发布