JS class Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.