function say(msg,other,garbage){ alert(arguments[1]);//world var other = 'nice to meet you!'; var msg; alert(arguments.length); alert(msg);//hello alert(other);//nice to meet you! alert(arguments[1]);//nice to meet you! alert(garbage);//undefined } say('hello','world');
function say(msg,other,garbage){ //先对函数声明的变量进行'预解析',内部执行流程,它是是不可见的 var msg = undefined; var other = undefined; var garbage = undefined; //再对函数内部定义的变量进行'预解析' var other = undefined;//很明显,此时这个定义已经无意义了。 var msg = undefined;//无意义 //对实际参数进行赋值操作 msg = new String('hello');//arguments的会将所有实际参数当作对象看待 other = new String('world'); //正式进入函数代码部分 alert(arguments[1]);//world other = 'nice to meet you!'; //var msg;这个已经被预解析了,因此不会再执行 alert(arguments.length);//2 alert(msg);//hello alert(other);//nice to meet you! alert(arguments[1]);//nice to meet you! alert(garbage);//undefined }