The difference between Jquery.extend and jQuery.fn.extend, in fact, can be seen from the two methods themselves. In many places, it is not detailed. Here is a detailed talk about the difference between. Tools/raw materials jquery library. JavaScript methods/Steps
We see jquery first as a class, so we can understand some of it.
Jquery.extend (), is the extension of the jquery class.
Suppose we think of the category jquery as human beings, can eat water can run can jump, and now we use jquery.extend this method to expand a singing skills to this class. In this case, whether it is a man, a woman, xx people ... can inherit this skill (method).
You can write the following diagram:
Then: $.liu (); So you can print out the string "Liu"
The code is below:
What does that mean? Liu () becomes the method (object) of the jquery class itself. He can "sing" now.
But, this ability, only the category of JQuery, which represents humanity, can use it. You personally want to use, you dick and Harry Harry hemp Six, you a grass people can represent all mankind.
So, this extension is the so-called static method. is only related to the class itself. It's okay to follow your specific instantiation object.
Let's look at the JQuery.fn.extend () method.
From the literal understanding, this expansion is the Jquery.fn method.
What the hell is Jquery.fn?
The source code is as follows
Oh, the original Jquery.fn=jquery.prototype, is the prototype AH.
That's a glance, JQuery.fn.extend expands the method of the JQuery object (the prototype).
What the object is. Is the instantiation of the class, for example
$ ("#abc")
This thing is an instanced jquery object.
That is to say, the method that JQuery.fn.extend expands, you have to use on the JQuery object above only then. He had to be Dick and Harry Wang Six of these instantiated objects to use.
That's the way it's supposed to be (assuming XYZ () is an extended approach):
$ (' selector '). XYZ ();
If you use $.XYZ (), it will make a mistake.
The code looks at the following picture:
The difference between the top and the other is at a glance.
In fact, jquery.extend () This method is mainly used to expand a global function, such as $.ajax () this, or expand a selector, such as $.fn.each (), when the selector.
Most plugins are made with JQuery.fn.extend ().