The difference between Jquery.extend and jQuery.fn.extend

Source: Internet
Author: User
Tags extend jquery library

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 ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.