Front-End Engineers-jquery-understand $.extend (), $.fn.extend (), $.fn,

Source: Internet
Author: User

The following is their own understanding, welcome to learn from the small partners to correct, thank you thank you

1.jquery.fn.extend (object): Commonly used to make plugins

Official explanation: A jquery plugin is simply a new method, which we use to extend JQuery ' s prototype object. (A new simple jquery plugin that we used to extend the jquery prototype object)

As soon as you see the extended prototype object, it's clear that you're adding a method to the jquery prototype, and the resulting jquery instance can be used in this way through the rules of the prototype chain.

<Script>        $(function() {$.fn.extend ({min:function(A, b) {returna<b?a:b; }, Max:function(A, b) {returna>b?a:b;            }            }); Console.log ($.min (1, 2)); //Error: $.min is not a functionConsole.log ($ ("P"). Min (1, 2)); //1        }); </Script>        

2.jquery.extend (object)

Official explanation: Extend the jquery object itself. Used to add new functions to the jquery namespace.

Extension object itself, then the instance is not found for these methods

<Script>        $(function() {$.extend ({min:function(A, b) {returna<b?a:b; }, Max:function(A, b) {returna>b?a:b;            }            }); Console.log ($.min (1, 2)); //1Console.log ($ ("P"). Min (1, 2)); //Error: $ (...). Min is not a function }); 

3. Jquery.fn (object)

Why put in the last say, please draw on this small partner's share, thank this small partner, borrow your address,

Http://caibaojian.com/jquery-extend-and-jquery-fn-extend.html

Abstract: For reference to the above address, the original will poke that address

Jquery.fn = Jquery.prototype = {Init:function (selector, context) {//....//...};
So the extension of the method, to write in the extend inside, not to change the prototype, a big thing

Front-End Engineers-jquery-understand $.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.