1.arguments is of course only meaningful in the function body, ARGUMENTS.LENGTH returns the number of arguments passed in the function.
<script type= "Text/javascript" >
Window.onload = function () {
(Function (arg1, arg2) {
alert (arguments.length); 0
alert (arguments.callee.length);//2
})();
}
</script>
Arguments only makes sense in the function body, ARGUMENTS.LENGTH returns the number of arguments passed in the function, such as what I have not passed in here, but directly run an anonymous function, then the first alert must be ' 0 ', Again, Arguments.callee returns the function of the call itself, and for an anonymous function, it can be arguments.callee to get its own reference. Here Arguments.callee.length returns the number of arguments the function expects to pass in, so that the second alert is ' 2 ', if this is a function with a name, such as a function named MyTest, Then you can directly mytest.length to get the number of arguments that should be passed in.
2. The value of the formal parameter is always synchronized with the value in the arguments parameter array corresponding to one by one.
function Doadd (NUM1, num2) {
NUM1 = 10;
Alert (arguments[0]);
}
Doadd (5, 5); Get 10
Instead
function Doadd (NUM1, num2) {
Arguments[0] = 10;
Alert (NUM1 + num2);
}
Doadd (5, 5);//Get 15
Note: In strict mode, the above procedure is wrong, cannot rewrite the arguments value inside the function, will error.
All parameter passes are passed by value, not by reference.
3. Inside the function, you can call it in the form of an array of arguments parameters. This means that the named parameter is not required, just for convenience.
function say () {
Alert (Arguments[0] + ' say ' + arguments[1]);
}
Say (' Xiao ', ' hello ');
JavaScript Arguments objects