<!DOCTYPE HTML>
<html>
<body>
<script>
sayHi(1,2,3)
function sayHi(x,y,z) {
alert("1:"+arguments[0]);// alert 1 as expected
alert("2:"+arguments[1]);// alert 2 as expected
alert("3:"+arguments[2]);// arert 3 as expected
[].shift.call(arguments);
[].shift.call(arguments);
[].shift.call(arguments);
alert("4:"+x); // alear 3, why?? :/
alert("5:"+y); // alert 3, why?? :/
alert("6:"+z); // alert 3, why?? :/
alert("7:"+arguments[0]); // undefined, no x any more :/
alert("8:"+arguments[1]); // undefined, no y any more :/
alert("9:"+arguments[2]); // undefined, no z any more :/
}
</script>
</body>
</html>
I understand that there is a special pseudo-array inside each function called arguments. The code above shift the first element of the arguments, but when I try to alert the value of parameters x,y,z, all the values are 3 instead of undefined. If there is link between arguments and parameters, then arguments[0] -> x, arguments[1]->y, arugments[2]->z, how can arguments[0],arguments[1],arguments[2] all become undefined while parameters x,y,z all be 3??