The extend method of jQuery and the jQueryextend Method

Source: Internet
Author: User
Tags shallow copy

The extend method of jQuery and the jQueryextend Method

Extend in jq is often asked during interviews. Today I will summarize three methods of extend usage comparison, which may be incomplete. I hope you can give me some advice,

Usage 1: $. extend ({}),Add a method for the jQuery class, which can be understoodExtensionStatic Method

    

Usage 2: $. fn. extend ({}) plug-in,Extension of jQuery. prototype. When it comes to plug-ins, you have to talk about another method.$. Fn. method = function (){}

  1.$. Fn. method = function () {} can define a method.

    

2.$. Fn. extend ({}) defines multiple methods.

It must be instantiated: $ (). toChange (), so its prototype method can be used.

    

 $. Extend ({}) -- Static Method and$. Fn. extend ({}) -- Differences Between instance methods. $ is short for jQuery.

1:The call of jQuery. extend () does not extend the method to the instance of the object. The method to reference it also needs to be implemented through the jQuery class.

2:The call of jQuery. fn. extend () extends the method to the prototype of the object. Therefore, when instantiating a jQuery object, it has these methods,

  3: jQuery. fn. extend = jQuery. prototype. extend

Usage 3: Inherit. Shallow copy and deep copy

1. Copying $. extend (a, B) a using B's attributes

2. Deep copy $. extend (true, a, B) a uses B's attributes

3.No matter how many objects follow, it will become the attribute of the first object.

   

 

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.