Tag: Type access return select Execute his SPAN init entry
In the general usage of jquery, the execution of "$ ()" Returns a JQuery object, which is defined in the source code:
... var function () { returnnew= Jquery.prototype;
The following conclusions can be drawn:
1, JQuery.fn.init () is jQuery.prototype.init ();
2. The init () function is a constructor, which is a jquery object created by invoking it, defined in the prototype of jquery ();
... var function (){ ... return This = Jquery.fn;
The following conclusions can be drawn:
1. The init () constructor finally returns a reference to the new object;
2. The prototype of the Init () is covered with the original of jquery ().
The question now is, why does jquery write like that?
Look again, our goal is to create a jquery class that contains a series of callable functions that instantiate this class to get the jquery object, which it can write:
var function () { function() { ...} var new jQuery ();
Obviously, jquery is not like this, he uses no new constructs, like this:
var function () { returnnewfunction() { ...} var function (){ ... return This function() { ...}
However, if this is the case, the jquery function is just an entry, and the Init function is the real implementation, so jquery puts Init () in Jquery.prototype (), which is:
var function () { returnnewfunction() { ... function (){ ... return This ; function (){ ...}
At this point, there is another problem: the newly created object cannot access the other properties in Jquery.prototype (), and the workaround is to pass the Jquery.prototype to JQuery.prototype.init.prototype
var function () { returnnewfunction() { ... function (){ ... return This ; = Jquery.prototype;
The entire process for creating a jquery object is as follows:
Call the $ () method, call the JQuery.prototype.init () constructor, and return different jquery objects, depending on the selector. The same method in different jquery objects is written in Jquery.prototype. Pass Jquery.prototype to JQuery.prototype.init.prototype so that the newly created object can access the generic method "
Creation of jquery objects (i)