1. What is an array of classes
Arguments is a class array object. Represents a list of arguments passed to a function.
Let's pass an example.
function Printargs () {
console. Log(arguments);
}
Printargs ("A", "a", 0, {foo: "Hello, Arguments"});
["A", "A", 0, Object]
Then look at what arguments represents, which represents all the arguments passed into the function when the function executes. In the above example, represents the incoming Printargs function in the four parameters, you can use Arguments[0], arguments[1] ... To get the individual parameters .
2. Operation of the arguments
Arguments.length
arguments is a class array object that contains a length property that can be used arguments.length to get the number of arguments passed into the function.
arguments to an array .
Array.prototype.silce.call (arguments); or use [].slice.call (arguments);
Modify the arguments value .
function foo(a) {
"Use strict";
console. Log(a, arguments[0]);
a = ten;
console. Log(a, arguments[0]);
arguments[0] = ;
console. Log(a, arguments[0]);
}
Foo(1);
// 1 1//10 1//10 20
Examples of non-strict patterns:
function foo(a) {
console. Log(a, arguments[0]);
a = ten;
console. Log(a, arguments[0]);
arguments[0] = ;
console. Log(a, arguments[0]);
}
Foo(1);
// 1 1//10 10//20 20
In strict mode, the arguments in the function are not associated with the arguments object, and modifying one value does not change the other. In non-strict mode, the two affect each other.
3.
array and class array objects
An array has one basic characteristic: an index. This is not the general object.
Const OBJ = {0: "A", 1: "B"};
Const ARR = ["A", "B"];
We use obj[0], arr[0] to get the data we want, but the way we get the data is really different. OBJ[0] is the use of the object's key-value pairs to access data, while Arr[0] is the index of the use of the array. In fact, the only difference between an object and an array is that the property of object is a string, and the index of the array is number.
Here's a look at the class array object.
the characteristic of a pseudo-array is that it looks like an array, contains a set of data, and has a length property, but does not have any method of array. In particular, the length property is a nonnegative integer, the upper limit is the maximum number that can be accurately expressed in JavaScript, and the length value of the class array object cannot be changed automatically .
JavaScript Arguments class Array