The Extend method of jquery "Three kinds of" _jquery

Source: Internet
Author: User
Tags extend shallow copy

JQ extend in the interview will often be asked, today I summarized a under the use of the extend three kinds of comparison, may not be full, I hope everyone pointing,

usage One: $.extend ({}) , adding methods for jquery classes that can be understood as extending static methods

Usage Two:$.fn.extend ({}) plugin , extend to Jquery.prototype, mention plug-in then you have to say another method $.fn.method = function () {}

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

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

need to instantiate: $ (). Tochange (), then its prototype method can be used

$.extend ({})--static method and $.fn.extend ({})--The difference between instance methods, $ is shorthand for jquery

The call to 1:jquery.extend () does not extend the method to an instance of an object, and the method that references it also needs to be implemented through the JQuery class

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

3:jquery.fn.extend = JQuery.prototype.extend

Usage three: Inherit. Shallow copy and deep copy

1. Shallow copy $.extend (A,B) a uses the properties of B

2. Deep copy $.extend (TRUE,A,B) a uses the properties of B

3. The properties of the first object, regardless of the number of objects behind it

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!

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.