Extend and FN. Extend of jquery

Source: Internet
Author: User
 

 

Jquery provides two methods for development plug-ins:

Jquery. FN. Extend (object );

Jquery. Extend (object );

 

Jquery. Extend (object); adds a new method to the class to extend the jquery class itself.

Jquery. FN. Extend (object); add a method to the jquery object.

 

What is fn. View jqueryCodeIt is not difficult to find out.


Jquery. fn = jquery. Prototype = {

Init: function (selector, context ){//....

//......

};

 

It turns out that jquery. fn = jquery. prototype. It is certainly no stranger to prototype.

 

Although JavaScript does not have a clear concept of a class, it is more convenient to use a class to understand it.

Jquery is a well-encapsulated class. For example, we use the statement $ ("# btn1") to generate a jquery class instance.

 

Jquery. Extend (object); adding class methods to the jquery class can be understood as adding static methods. For example:

 

$. Extend ({

Add: function (a, B) {return a + B ;}

});

 

Add a "static method" for jquery as add, and then you can use this method in the place where jquery is introduced,

$. Add (3, 4); // return 7

 

Jquery. FN. Extend (object); the extension to jquery. prototype is to add "member functions" to the jquery class ". Jquery class instances can use this "member function ".

For example, we want to develop a plug-in and create a Special edit box. When it is clicked, the content in the current edit box of alert is displayed. You can do this:

Java code
  1. $. FN. Extend ({
  2. Alertwhileclick: function (){
  3. $ ( This ). click (function () {
  4. alert ($ ( This ). val ();
  5. });
  6. }
  7. });
  8. $ ("# Input1"). Alertwhileclick ();// <Input id = "input1" type = "text"/>

 

 

$ ("# Input1") is a jquery instance. When it calls the member method alertwhileclick, the extension is implemented. When it is clicked, the content in the current edit is displayed.

 

In the real development process, of course, we will not do such a small plug-in. In fact, jquery has provided a wide range of operations.CompositionFile, event, CSS, Ajax, and effect methods can be combined to develop more niubility plug-ins.

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: info-contact@alibabacloud.com 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.