jquery converts a DOM to an array of objects

Source: Internet
Author: User

jquery converts a DOM to an array of objects

1, jquery object (this point) is actually a key-value pair of data collection, a common hashtabel. In a collection, a custom key name can be either a letter or an integer, indexed by {name1: "value1", Name2: "value2"}[name2] and {0: "value1", 1: "value2"}[1] There is no difference, The latter data structure has nothing to do with arrays (array), what about "[document]"?

2, the jquery framework, in which the filter DOM object is stored in the properties of the jquery object while the constructor JQuery.fn.init constructs the jquery object, stores the DOM element data key in the form of 0, 1, 2 ... and defines a length property that is designed to facilitate (compatible) the Jquery.each of manipulating DOM elements. Look at the following concise simulation to understand that:
Jquery.each = function (object, callback, args) {//object can be an array array:[...] can also be objects object:{0:dom1, 1:dom2, 2:dom3 ... length:3+}
         for (var i = 0; i < object.length; i + +) {
               callback.call ( Object[i], I, arg
        }
          return Object
}
Jquery.each (this, function (I, ARG) {//Here This is the JQuery object, passing through the key name 0, 1, in the Jquery.each, 2. Circular indexing makes it easy to get each DOM element (DOM object) to handle the manipulation.
        method ..... .......
       //operations 1 (or bulk operations) DOM elements and returns the JQuery object (this).
}, Arg)

3, the problem is some of the introduction of jquery objects in the tutorial, the key name is 0, 1, 2 ... Data structure that customizes the length attribute is separated from the jquery object called "Class array", the concept of fraught, the superfluous, the fog

<script src= "Http://code.jquery.com/jquery-1.6.2.js" ></script>
<script>
Alert (Object.prototype.toString.call ($ (document)) = = ' [Object Array] '); ???
Alert ($ (document) [0]===document);
</script>

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.