The difference between $.extend,$.fn.extend,$.fn

Source: Internet
Author: User

Jquery.extend (object)

Adding a class method to the jquery class can be understood as adding a static method. Such as:

jQuery. Extend ({min: function(a, b) { return a < b ? a : b; },max: function(a, b) { return a > b ? a : b; }});jQuery.min(2,3); //  2 jQuery.max(4,5); //  5
OBJECTJ query.extend (Target, Object1, [objectn])

Extend an object with one or more other objects, returning the object being extended

ar settings = { validate: false, limit: 5, name: "foo" }; var options = { validate: true, name: "bar" }; jQuery. Extend (Settings , options); result:settings == { validate: true, limit: 5, name: "bar" }

JQuery.fn.extend (object);

The extension to Jquery.prototype is to add "member functions" to the jquery class. An instance of the jquery class can use this "member function". For example, we want to develop a plugin, make a special edit box, when it is clicked, then alert the contents of the current edit box. You can do this:

$.fn.extend ({alertwhileclick:function () {$ (this). Click (function () {                      Alert (This). Val ());                });       }       }); $ ("#input1"). Alertwhileclick (); On the page is:

The difference between $.extend,$.fn.extend,$.fn

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.