预编译

一、js运行三步:语法分析-> 预编译 ->解释执行

二、预编译四部曲

1.创建AO对象(Activation Object):执行期上下文
2.找形参和变量声明,将他们作为AO属性名,值为undefined
3.将实参值赋给形参
4.找函数声明,值赋予函数体
 
a=100;
function demo(e){
    function e(){}
    arguments[0]=2;
    console.log(e);
    if(a){
        var b=123;
    }
    function c(){}
    var c;
    a=10;
    var a;
    console.log(b);
    f=123;
    console.log(c);
    console.log(a);
    
}
var a;
demo(1);
console.log(a);
console.log(f);

// GO:{
//     a:undefined,100
//     demo:function demo(){},
//     f:123
// }
// AO:{
//     e:undefiend,1,function e(){},2
//     b:undefiend,
//     c:undefined,function c(){}
//     a:undefined,10
// }
//打印结果:
//2,undefined,function c(){},10
//100,123

 

posted @ 2018-08-08 17:30  yuesu  阅读(208)  评论(0编辑  收藏  举报