Class array-[Array-like]: Objects
1. What ' s Array-like
class arrays and arrays are very similar, but many methods of arrays are not available, which is awkward.
These data, such as arguments and NodeList, have an ordered set of attributes, such as length and subscript, but are not arrays. This is called the Array-like (class array/pseudo-array). For Array-like we can use a cross-prototype chain to operate, Eg:Array.prototype.slice.call (arguments, 0); This is also the way to convert Array-like into an Array.
2. Build Your own Array-like
is to add the native method of the Array to the Object you created.
If you do not add the length property to a. A[0] and a[1] will be overwritten when push is made.
3. How to determine if an Array is not
typeof to judge the result of the array is ' object ', so many LIB use the duck typing (duck type detection) way, it is judged by the condition is: when the length property of the object is a number, and the Splice property is a function, then this An object is an array.
JS class Array