预编译四步
1,创建AO对象(创建执行期上下文)
2,找形参和变量声明,在AO对象(创建执行期上下文)里面,作为属性名,值为undefined
3,把实参赋值给形参
4,找函数声明,值为函数体
实例
function fn(a,b){
console.log(a);
var a = 123;
function a(){}
console.log(a)
function c(){}
var d = 789;
}
预编译:
第一步,A0{
}
第二步,A0{
a:undefined;
b:undefined;
d:undefined;
}
第三步,A0{ //把实参赋值给形参;
a:111;
b:222;
d:undefined;
}
第四步,A0{ //找函数声明,值为函数体;
a:function a(){};
b:222;
c:function c(){}
d:undefined;
}
函数执行
fn(111,222)
// console.log(a) 此时a值为function a(){};
// a = 123;
// 在打印 console.log(a); 此时a值为123;
//d = 789; 此时d值为789;