[Learning jquery] learn more about jquery (1)-jquery objects

Source: Internet
Author: User

Question: jquery has been used for two years, and JS has been used for three years. I think I understand it a little better. It is no longer a layman. So I should also write a blog and systematically sort out the learned knowledge. Learn new things with a warm understanding, develop your own blog writing habits, improve your writing skills, and prepare for future transformations.

Everything is simplified

 
$ (Document). Ready (Function(){
 
VaRJqobj = $ ("Div");
 
});

What is jqobj? Firebug gets that it is such an object. Through jqobj. constructor, the object instead of array is obtained. It must be a pseudo array. (What is a pseudo array? Pseudo array ). Well, let's go into it and see what object jquery returns.

Below is the center of the simple version I picked from jquery.Code:

 
(Function(){
VaRJquery = Window. jquery =$ = Window. $ =Function(Selector, context ){
 
Return NewJquery. FN. INIT (selector, context );
 
}
 
$. Prototype = jquery. fn = jquery. Prototype = {
 
Init:Function(Selector, context ){
 
If(Selector. nodetype = 1 ){
 
This[0] = selector;
 
This. Length = 1;
 
Return This;
 
}
 
 
}
 
}
 
Jquery. Prototype. init. Prototype = $. Prototype;
 
 
 
})();

The returned object is the same as that of jquery. However, there are not as many attributes and support methods as jquery currently. Let's break down the $ ("Div") action.

RunFunction(Selector, context ){Return NewJquery. FN. INIT (selector, context);}. context is the context. If this parameter is not specified, jquery defaults to document. We will ignore it temporarily.Return NewJquery. FN. INIT (selector, context); in this way, we can draw a preliminary conclusion. The response is an instance of the jquery. FN. init method class.

At this time, we have doubts. Because there are many methods for returning objects returned by jquery, such as HTML (), each (), and so on. Well, the key lies inJquery. FN. init. Prototype = jquery. FN;This sentence is equivalent to the original type of the init class that inherits the jquery class. However, it is not completely inherited here. It just gets the jquery prototype method.

Add the following method to jquery. prototype:

 
, CSS:Function(Cssjson ){
 
For(VaRI = 0; I <This. Length; I ++ ){
For(VaRStylenameInCssjson ){
 
This[I]. Style [stylename] = cssjson [stylename];
 
}
 
}
 
Return This;
 
}
 
In this way, we found that the $ (document) object has a CSS method. (currently, our class library only supports DOM elements, and other selector will be added later)
 
 
 
 
 
 

Summary:

1. The jquery object is a pseudo array and is an instance of the jquery. FN. init class.

2. The jquery object is a member of the init class this + jquery. prototype.

3. Use jquery. FN. Extend ({......}); Extended member.

Reference http://www.cnblogs.com/snandy/category/285213.html

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.