1(function(window, undefined) {2 varJQuery = (function(){3 varJQuery =function(selector) {4 return NewJQuery.fn.init (selector);5 };6 7 //here fn is the alias of prototype, and the later code extension FN is the extension PROTOTYPE,FN writes it short.8 //If a large number of Prototype,prototype are referenced later because they are keywords, they cannot be compressed .9Jquery.fn = Jquery.prototype = {Ten Constructor:jquery, One //This is a constructor function AInit:function(Selector, context) { - varRoot; - //If you don't have root, start looking for it from document theRoot = Context | |document; - // - varParts = Selector.split (""),//separating selectors with spaces -query = Parts[0],//Take out the first paragraph of the result + //Slice returns a new array consisting of the 1th item to the last item - //join converts each element in the array to a string and joins it with a space to form a string object . +Rest = Parts.slice (1). Join (""), AElems = root.getelementsbytagname (query),//find elements that match the first segment selector atresults = [];//Initializes an array to hold the query results - - for(vari = 0; i < elems.length; i++){ - if(rest) { - //recursive lookup, with Elems[i] as the context, with rest as the selector expression - //Concat creates a copy of the original array and adds the result of the find to the end of results, where the reference to the copy is stored back into the results inResults =Results.concat (Find (rest, elems[i])); - } to Else{ + //Save the found element on the results array - Results.push (Elems[i]); the } * } $ //true jquery returns is not an array object, it is an object of class arraysPanax Notoginseng returnResults//returns the Array object - the } + }; AJQuery.fn.init.prototype =Jquery.fn; theJquery.extend = JQuery.fn.extend =function(){ + varOB = Arguments[0]; - for(varPinchob) { $ if(Ob.hasownproperty (P) && (! This. hasOwnProperty (p))) { $ This[p]=Ob[p]; - } - } the }; - Wuyi //used to extend the global object, so do not jQuery.fn.extend the Jquery.extend ({ -Isfunction:function () { Wu if(typeofArguments[0] = = "function") - return true; About Else $ return false; - } - }); - A Jquery.extend ({ +Isfrom:function(){ the returnArgument[0].constructor = = Arguments[1]; - //return arguments[0] instanceof arguments[1]; $ }}); the the the Jquery.extend ({ theeachfunction(obj,callback) { - for(vari = 0; i < obj.length; i++){ inCallback.call (obj | |NULL, Obj[i], I, obj); the } the } About }); the /* the for an HTML document, getElementsByTagName returns a Htmlcollection object that is similar to the NodeList object, which is implemented in C + + the See "JS elevation" P257 + return Jquery.makearray (document.getElementsByTagName (selector)); - */ the Jquery.extend ({BayiMakearray:function(array, results) { the //the array is htmlcollection to the image theArray = Array.prototype.slice.call (array, 0 ); - if(results) { - results.push.apply (results, array); the returnresults; the } the the returnArray; - } the }); the returnJQuery; the })();94Window.jquery = window.$ =JQuery; the}) (window);
Currently only tag selectors are supported, such as "div", "div p". and $ ("div") returns an array object, different from the actual jquery
Homemade jquery (3)