[your jQuery? Is your jQuery] (two) -- jQuery

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Objective:


What is the jQuery object, jQuery object and prototype method and static method


Analytical:

Copy the &ldquo on a two part of the code; ”:

A,

 1  (function (window, undefined) {
 2    var jQuery = window.jQuery = window.$ = function (selector, context) {
 3      return new jQuery.fn.init(selector, context);
 4     }
 5     jQuery.fn = jQuery.prototype = {
 6          init: function (selector, context) {
 7              },
 8              jquery: "xxx",
 9              css:function(){
10              },
11              attr:function(){
12              },
13       } 
14  jQuery.fn.init.prototype = jQuery.fn;
15  })(window)
16  alert($().jquery)    //Successfully constructed $(OO).Xx this stuff  

Constructed out of something that is a jQuery object, which is an instance of the new of a jQuery.fn.init prototype method, this example is the jQuery object was obtained, the red part is in the code.

So what is a static method.?

First look at a function:

Two,

 1  jQuery.extend = jQuery.fn.extend = function (obj, target) {
 2         target = target || this; //If you do not pass target, the default extension, which is jQuery
 3         for (var name in obj) {
 4             target[name] = obj[name];
 5         }
 6         return target;
 7  }
 8  jQuery.extend({
 9        each:function(){},
10        trim:function(){}
11 })

Of course, the source of extend than the cow force, I just put forward the replication properties of simple parts, and this new method enough I jQuery or property for the development of new things, is a static method, also is not instantiated can use, like $.each (), $.trim () the.

So, understanding the prototype method and static method, we can make snap to expand, to the jQuery object was born some things, you jQuery.prototype={} to write, to jQuery.XX directly if extended, in jQuery.extend ({}) write.


(this so far, other content unfinished, to be continued……)


The next section tips:

The key to the! Using Sizzle ideas from right to left, to create their own CSS selector

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Harvey at November 23, 2013 - 7:41 AM