一、 函数预编译四部曲
-
创建AO对象
-
找形参和变量声明,将变量和形参名作为AO属性名,值为undefined。
-
将实参值和形参统一
-
在函数体里面找函数声明,值赋予函数体
二、练习题
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript">
function test(){
console.log(b)
if(a){
var b = 100;
}
c = 234;
console.log(c);
}
var a;
test();
a = 10;
console.log(c);
</script>
</body>
</html>
执行分析
首先生成GO
GO{
a:undefined
test:function test(){}
}
执行test()行时生成AO{} 不要受 if 的影响。
AO{
b:undefined
}
//第一个输出为undefinded
接着执行if()模块
此时a为undefined,if()模块为false
接着GO{}中添加一个属性c,值为234