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){ //先對(duì)函數(shù)聲明的變量進(jìn)行'預(yù)解析',內(nèi)部執(zhí)行流程,它是是不可見的 var msg = undefined; var other = undefined; var garbage = undefined; //再對(duì)函數(shù)內(nèi)部定義的變量進(jìn)行'預(yù)解析' var other = undefined;//很明顯,此時(shí)這個(gè)定義已經(jīng)無意義了。 var msg = undefined;//無意義 //對(duì)實(shí)際參數(shù)進(jìn)行賦值操作 msg = new String('hello');//arguments的會(huì)將所有實(shí)際參數(shù)當(dāng)作對(duì)象看待 other = new String('world'); //正式進(jìn)入函數(shù)代碼部分 alert(arguments[1]);//world other = 'nice to meet you!'; //var msg;這個(gè)已經(jīng)被預(yù)解析了,因此不會(huì)再執(zhí)行 alert(arguments.length);//2 alert(msg);//hello alert(other);//nice to meet you! alert(arguments[1]);//nice to meet you! alert(garbage);//undefined }