1. In JavaScript, the arguments object is a very special object and is actually a built-in property of the current function. Arguments is very similar to array, but is not actually an array instance. Can be confirmed by the following code (of course, in fact, in the function funcarg, call arguments is not necessary to write a funcarg.arguments, directly written arguments).
ARRAY.PROTOTYPE.TESTARG = "Test";
function Funcarg () {
alert (FUNCARG.ARGUMENTS.TESTARG);
Alert (funcarg.arguments[]);
}
Alert (new Array (). Testarg); Result: "Test"
2, the length of the arguments object is determined by the number of arguments rather than the number of parameters. A formal parameter is a variable that arguments the memory space inside a function, but it does not overlap with the memory space of the object. For both arguments and values, the values are synchronized, but for one of them that has no value, the value of the condition is not synchronized. The following code can be validated.
function f (A, B, c) {
alert (arguments.length);//Result: ""
a =;
Alert (arguments[]); Result: ""
arguments[] = "Qqyumidi";
alert (a); Result: "Qqyumidi"
alert (c);//Result: "undefined"
C =;
Alert (arguments[]); Result: "Undefined"
}
3. By declaring and invoking features of functions in JavaScript, you can see that functions in JavaScript are not overloaded.
Depending on the overload in other languages: "The function return value is different or the number of parameters is different", we can draw the conclusion that:
First: The declaration of a JavaScript function has no return value type;
Second: The number of formal parameters in JavaScript is strictly in order to facilitate the operation of variables in the function, actually the argument is already stored in the arguments object.
In addition, the JavaScript function itself is an in-depth understanding of why functions in JavaScript cannot be overloaded: In JavaScript, functions are objects, function names are references to functions, or function names themselves are variables. The function declarations and function expressions shown below are actually the same (without considering the difference between a function declaration and a function expression), which is very helpful in understanding the feature that functions in JavaScript are not overloaded.
function f (a) {return
A +;
}
function f (a) {return
a-;
}
Without considering the difference between the function declaration and the function expression, it is equivalent to the following
var f = function (a) {return
A +;
}
var f = function (a) {return
a-;
4, there is a very useful property in the arguments object: callee. Arguments.callee returns the current function reference for this arguments object. It is recommended to use Arguments.callee instead of the function name itself when using recursive calls to functions.
As follows:
function count (a) {
if (a==) {return
;
}
Return a + Arguments.callee (--a);
}
var mm = count ();
alert (mm);
The above is a small set up to introduce the JavaScript in the arguments object, I hope to help you, if you find in the reference process to have any questions please give me a message, small series will promptly reply to everyone, here also thank you for the cloud Habitat Community website support!