I knew long ago that I could convert arguments to an array: .slice.call (arguments), because
Arguments is a class array object, so you can use it. But I never knew what it was called Class array objects (Array-like objects)
First look at some of the sample code I wrote:
The first few are manipulating strings, well, strings can also be thought of as class array objects. But that B-object back there
is also a class array object.
The explanation in reading:
There are only these two simple rules.
So why arguments, strings, and the above B-objects can be thought of as class array objects?
They all have a valid length property (a positive integer between 0 and 2**32-1).
The value of the length property is greater than their maximum index.
Well, it's wrong, it's ' ab ', because it violates the rules. 2:length property is 3,
The maximum index value is 4 larger than the length property. So the performance is not normal.
Too powerful, as if only to define an interface, as long as the interface is met, you can take advantage of all the methods of the array.
Well, not all the way, Array.prototype.concat.
is not available, because it is connected to two arrays, you are not an array must not be able to use it.
Another small problem is that the string creation is immutable (immutable), so how you toss it is immutable.
But the book simply does not explain why it fits these two conditions as a class array object, and the author of the book
It's a member of the ECMAScript committee, so it's basically believable. As for why meet these two conditions can be regarded as an array of objects, I do not know, Google search for a half-day also did not see any reasonable explanation.
The above mentioned is the entire content of this article, I hope you can enjoy.