步骤
- 创建ao对象
- 找形参和变量声明,作为ao对象的属性名,值为undefined
- 实参和形参相统一(也就是将形参的值改为实参传来的值)
- 找函数声明,会覆盖变量声明,也就是会覆盖之前的实参和undefined;注意区分函数声明和函数表达式 var b = function(){}则属于函数表达式,不影响值的变化
- 做完以上步骤,然后再逐行执行代码
习题一:
function ao(a,c){
console.log(a) //function a(){}
var a = 123
console.log(a) //123
console.log(c) //function c(){}
function a(){}//函数声明
if(false){//false没有执行
var d = 678
}
console.log(d)//undefined
console.log(b)//undefined
var b = function(){}//函数表达式 赋值给b
console.log(b)//function(){}
function c(){}//函数声明
console.log(c)//function c(){}
}
ao(1,2)
进入逐行代码之前的各属性值
ao:{
a:undefined(形参) 1(实参) function a(){}(步骤四)
c:undefined(形参) 2(实参) function c(){}(步骤四)
d:undefined
b:undefined
}
习题二:
function test(a,b){
document.write(a);//1
c=0;
var c;
a=3;
b=2;
document.write(b);//2
function b(){}
function d(){}
document.write(b);//function b(){}
}
test(1)
ao{
a:undefined 1
b:undefined function b(){}
c:undefined
d:undefined function d(){}
}