Obviously, can do this step, its implementation is quite complicated, this implementation is its init method, jQuery constructor. It functions as the version upgrade and upgrade, also more and more long.
the 2009-01-13 release of version 1.3

init: function (the selector, context) {
//Make sure that a selection was provided
the selector=the selector | | document;
//processing node parameter, directly add attributes to the new instance
if (selector. NodeType) {
this [0]=the selector;
this. Length=1;
enclosing context=the selector;
return this;
}

//processing string parameters the if (typeof selector==="string") {
//decide whether to HTML fragments or ID.
var match=quickExpr exec (selector);
if (match &&(match [1] | |! Context)) {
//if they are fragments of HTML, converting a node structure array
if (match [1])
the selector=jQuery. The clean ([match] [1], the context).
//if the ID is to find the element, if found in an empty array
the else {
var elem=document. The getElementById (match [3]).
//Make sure the an element was located in the
if (elem) {
/IE/processing and Opera confuse ID and the NAME of the bug
if (elem. ID!=match [3])
return jQuery (). The find (the selector);
var ret=jQuery (elem);
ret. Context=document;
ret. The selector=the selector;
return ret;

} the selector=[];

}} else
//using the Sizzle with other CSS expressions, and returns an instance
return jQuery (context). Find (the selector);
//processing function parameters, direct domReady
} else if (jQuery. IsFunction (selector))
return jQuery (document). Ready (selector);
//processing jQuery object parameters, simply its two attributes assigned to a new instance of
if (selector. The selector &&selector. The context) {
this. The selector=selector. The selector.
this. Context=selector. The context;

}//will get node arrays, turn them into the instance element with setArray method
return this. SetArray (jQuery. MakeArray selector ());
},

the 2009-02-19 release of version 1.32

init: function (the selector, context) {
//Make sure that a selection was provided
the selector=the selector | | document;
//processing node parameter, directly add attributes to the new instance
if (selector. NodeType) {
this [0]=the selector;
this. Length=1;
enclosing context=the selector;
return this;
}

//processing string parameters the if (typeof selector==="string") {
//decide whether to HTML fragments or ID.
var match=quickExpr exec (selector);
if (match &&(match [1] | |! Context)) {
//if they are fragments of HTML, converting a node structure array
if (match [1])
the selector=jQuery. The clean ([match] [1], the context).
the else {
var elem=document. The getElementById (match [3]).
//if it's ID, then find this element, if found into an empty array
if (elem &&elem. ID!=match [3])
return jQuery (). The find (the selector);
//here for version 1.3 to do some optimization, more concise
var ret=jQuery (elem | | []);
ret. Context=document;
ret. The selector=the selector;
return ret;

}} else
//using the Sizzle with other CSS expressions, and returns an instance
return jQuery (context). Find (the selector);
//processing function parameters, by using the domReady operator
} else if (jQuery. IsFunction (selector))
return jQuery (document). Ready (selector);
//processing jQuery object parameters, simply its two attributes assigned to a new instance of
if (selector. The selector &&selector. The context) {
this. The selector=selector. The selector.
this. Context=selector. The context;

}//done here for version 1.3 extensions, allow Jane elements on the set (HTMLCollection) and node set (NodeList),
//element array may be we use string conversion, also can be directly incoming
return this. SetArray (jQuery. IsArray (selector)? The selector: jQuery. MakeArray selector ());
},

the 2010-01-13 release of version 1.4

init: function (the selector, context) {
var match, elem, ret, doc.
//processing blank string, null, and undefined parameters (new), returns a very pure instance
if (!) the selector {
return this.

}//processing node parameter, directly add attributes to the new instance
if (selector. NodeType) {
enclosing context=this [0]=the selector;//write optimization
this. Length=1;
return this;
}

//processing string parameters the if (typeof selector==="string") {
//decide whether to HTML fragments or ID
match=quickExpr. The exec (selector);
if (match &&(match [1] | |! Context)) {
//if fragments of HTML
if (match) [1] {

//document object doc=(context? Context. The ownerDocument | | context: the document).
//if it's a single tag, direct use of the document. The createElement method to create this node and into the array
ret.=rsingleTag exec (selector);
if (ret) {
//if followed by a pure JS object, the corresponding property for this node added or style
if (jQuery. IsPlainObject (context)) {
the selector=[document. The createElement method (ret) [1]]. .
jQuery fn. Attr. Call (the selector, context, true);
} else {
the selector=[doc. The createElement method (ret) [1]].

}} else {
//shifted to buildFragment generated nodes (NodeList)
ret=buildFragment ([match] [1], [doc]);
the selector=(ret) cacheable? Ret. Fragments. CloneNode (true) : ret. The fragments). The.childnodes;

}} else {
//if the ID, is to find the element, if found in an empty array
elem=document. The getElementById (match [2]).
if (elem) {
/IE/processing and Opera confuse ID and the NAME of the bug
if (elem. ID!==match [2]) {
return rootjQuery. Find (the selector);

}//here also did some optimization, it is silly to generating a jQuery instance
this. Length=1;
this [0]=elem;

} enclosing context=document;
this. The selector=the selector;
return this;

}//if the character is very simple tag selector, that basic is not necessary to Sizzle, getElementsByTagName directly, very good optimized
} else if (! The context &&/^ \ w + $/test (the selector)) {
this. The selector=the selector;
enclosing context=document;
the selector=document. GetElementsByTagName (selector);
//if the second parameter does not exist or is a jQuery object, then use it or rootjQuery calls to find the target node (taking Sizzle line)
} else if (! The context | | context. The jQuery) {
the return (the context | | rootjQuery), find (the selector);
//HANDLE: $(expr, context)
//(which is just equivalent to: $(context).find(expr)
} else {
//如果第二个参数已指定为某元素节点,转为jQuery对象,走Sizzle路线
return jQuery( context ).find( selector );
}
//处理函数参数,直接domReady
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
//处理jQuery对象参数,简单地将其两个属性赋给新实例
if (selector.selector !==undefined) {
this.selector=selector.selector;
this.context=selector.context;
}
//这里又做了些许修改,缘于makeArray可以接受第二个参数(可以是数组或类数组,这时相当合并操作)
return jQuery.isArray( selector ) ?
this.setArray( selector ) ://内部用push方法,迅速将一个普通对象变成类数组对象
jQuery.makeArray( selector, this );
},

接着是广受欢迎的2010-02-13发布的1.42版

init: function( selector, context ) {
var match, elem, ret, doc;
//处理空白字符串,null,undefined参数
if ( !selector ) {
return this;
}
//处理节点参数
if ( selector.nodeType ) {
this.context=this[0]=selector;
this.length=1;
return this;
}
//处理body参数(新增)
if ( selector==="body" &&!context ) {
this.context=document;
this[0]=document.body;
this.selector="body";
this.length=1;
return this;
}
//处理字符串参数,分七种情形:
//①单个标签,带对象属性包 ---> jQuery.merge
//②单个标签,不带对象属性包 ---> attr + jQuery.merge
//③复杂的HTML片断 ---> buildFragment + jQuery.merge
//④ID选择器,与找到的元素的ID不同 ---> getElementById + Sizzle + pushStack
//⑤ID选择器,与找到的元素的ID相同 ---> getElementById + 简单属性添加
//⑥标签选择器 ---> getElementsByTagName + jQuery.merge
//⑦其他CSS表达式 ---> Sizzle + pushStack
if ( typeof selector==="string" ) {
match=quickExpr.exec( selector );
if ( match &&(match[1] || !context) ) {
if ( match[1] ) {
doc=(context ? context.ownerDocument || context : document);
ret=rsingleTag.exec( selector );
if ( ret ) {
if ( jQuery.isPlainObject( context ) ) {
selector=[ document.createElement( ret[1] ) ];
jQuery.fn.attr.call( selector, context, true );
} else {
selector=[ doc.createElement( ret[1] ) ];
}
} else {
ret=buildFragment( [ match[1] ], [ doc ] );
selector=(ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
}
return jQuery.merge( this, selector );
} else {
elem=document.getElementById( match[2] );
if ( elem ) {
if ( elem.id !==match[2] ) {
return rootjQuery.find( selector );
}
this.length=1;
this[0]=elem;
}
this.context=document;
this.selector=selector;
return this;
}
} else if ( !context &&/^\w+$/.test( selector ) ) {
this.selector=selector;
this.context=document;
selector=document.getElementsByTagName( selector );
return jQuery.merge( this, selector );
} else if ( !context || context.jquery ) {
return (context || rootjQuery).find( selector );
} else {
return jQuery( context ).find( selector );
}
//处理函数参数,直接domReady
} else if ( jQuery.isFunction( selector ) ) {
return rootjQuery.ready( selector );
}
//处理jQuery对象参数
if (selector.selector !==undefined) {
this.selector=selector.selector;
this.context=selector.context;
}
//无论是数组还是类数组(如NodeList),统统使用jQuery.makeArray来为实例添加新的元素
return jQuery.makeArray( selector, this );
},

另附上makeArray方法与merge方法,merge方法好神奇啊,

makeArray: function( array, results ) {
var ret=results || [];
if ( array !=null ) {
//The window, strings (and functions) also have 'length'
//The extra typeof function check is to prevent crashes
//in Safari 2 (See: #3039)
if ( array.length==null || typeof array==="string" || jQuery.isFunction(array) || (typeof array !=="function" &&array.setInterval) ) {
push.call( ret, array );
} else {
jQuery.merge( ret, array );
}
}
return ret;
},
merge: function( first, second ) {
var i=first.length, j=0;
if ( typeof second.length==="number" ) {
for ( var l=second.length; j first[ i++ ]=second[ j ];
}
} else {
while ( second[j] !==undefined ) {
first[ i++ ]=second[ j++ ];
}
}
first.length=i;
return first;
},

2011-01-23发布的1.5版,其init方法与1.42的变化不大:只有两处做了改动:

//1.42
- ret=buildFragment( [ match[1] ], [ doc ] );
- selector=(ret.cacheable ? ret.fragment.cloneNode(true) : ret.fragment).childNodes;
//1.5
+ ret=jQuery.buildFragment( [ match[1] ], [ doc ] );
+ selector=(ret.cacheable ? jQuery.clone(ret.fragment) : ret.fragment).childNodes;
//1.42
- return jQuery( context ).find( selector );
//1.5
+ return this.constructor( context ).find( selector );//目的就是为了不再生成新实例

2011-05-02发布的jquery1.6,变化不大,只是对HTML片断进行了更严密的判定:

//Are we dealing with HTML string or an ID?
if ( selector.charAt(0)==="<" &&selector.charAt( selector.length - 1 )===">" &&selector.length>=3 ) {
//Assume that strings that start and end with <> are HTML and skip the regex check
match=[ null, selector, null ];
} else {
match=quickExpr.exec( selector );
}

总体来说,jQuery的构造器已经做得非常之完美,基本上达到“改无可改”的地步了。但是要保证其高效运作,我们还需要一点选择器的知识与了解buildFragment方法的运作,因为这两个实在太常用了,但也是最耗性能的。


This concludes the body part