The code copy is as follows:
<script Language="JavaScript">
//The first parameter value.
function test(a,b,c,d){
alert(arguments[0]);
}
//Arguments[0] is actually a. Similarly, arguments[1] is b, c, d in turn
</script>
The code copy is as follows:
<script Language="JavaScript">
{
function function_Name(exp1,exp2,exp3,exp4)
{
var umber="";
umber=arguments.length;
alert(umber);
}
function_Name('a','b','c','d'); can all be called
// function_Name("a","b","c","d"); can be called
}
</script>
1. In JavaScript, the arguments object is a relatively special object, which is actually a built-in property of the current function. arguments are very similar to Array, but are not actually an Array instance. It can be verified by the following code (of course, in fact, in the function funcArg, it is unnecessary to write arguments as funcArg.arguments, just write arguments).
The code copy is as follows:
Array.prototype.testArg = "test";
function funcArg() {
alert(funcArg.arguments.testArg);
alert(funcArg.arguments[0]);
}
alert(new Array().testArg); // result: "test"
funcArg(10); // result: "undefined" "10"
2. The length of the arguments object is determined by the number of real parameters rather than the number of formal parameters. The formal parameters are variables that reopen memory space storage within the function, but they do not overlap with the memory space of the arguments object. When both arguments and values exist, the values are synchronized, but for one of them, the values are not synchronized for this valueless situation. The following code can be verified.
The code copy is as follows:
function f(a, b, c){
alert(arguments.length); // result: "2"
a = 100;
alert(arguments[0]); // result: "100"
arguments[0] = "qqyumidi";
alert(a); // result: "qqyumidi"
alert(c); // result: "undefined"
c = 2012;
alert(arguments[2]); // result: "undefined"
}
f(1, 2);
3. From the declaration and calling characteristics of functions in JavaScript, it can be seen that functions in JavaScript cannot be overloaded.
Based on the basis of overloading in other languages: "The return value of the function is different or the number of formal parameters is different", we can draw the above conclusion:
First: There is no such statement that the declaration of Javascript functions returns a value type;
Second: The number of formal parameters in JavaScript is strictly just to facilitate variable operation in functions. In fact, the actual parameters have been stored in the arguments object.
In addition, a deep understanding of why functions cannot be overloaded in JavaScript from the JavaScript function itself: in JavaScript, functions are actually objects, and the function name is a reference to the function, or the function name itself is a variable. For the function declaration and function expression shown below, the above is actually the same (without considering the difference between function declaration and function expression), it is very helpful for us to understand the characteristic that functions cannot be overloaded in JavaScript.
The code copy is as follows:
function f(a){
return a + 10;
}
function f(a){
return a - 10;
}
// Without considering the difference between function declaration and function expression, it is equivalent to the following
var f = function(a){
return a + 10;
}
var f = function(a){
return a - 10;
}
4. There is a very useful property in the arguments object: callee. arguments.callee returns the current function reference where this argument object resides. When using recursive calls to function, use arguments.callee instead of the function name itself.
as follows:
The code copy is as follows:
function count(a){
if(a==1){
return 1;
}
return a + arguments.callee(--a);
}
var mm = count(10);
alert(mm);