Introduction to the use of extend in jquery

Source: Internet
Author: User
Tags extend

  This article mainly describes how to use the extend in jquery, need friends can refer to the following

In jquery, the Extend extension method prototype is:    1, Extend (dest,src1,src2,src3 ...);   Its meaning is to src1,src2,src3 ... Merged into Dest, the return value is the merged dest, which shows that the method is modified to dest structure after merging. If you want to get the result of merging but do not want to modify the structure of dest, you can use:    2, var newsrc=$.extend ({},src1,src2,src3 ...) as follows. That is, "{}" as the Dest parameter.   This will be able to src1,src2,src3 ... To merge, and then return the merge results to NEWSRC.   The following example:      code is as follows: Var result=$.extend ({},{name: "Tom", Age:21},{name: "Jerry", Sex: "Boy"})     then the merged result   result={name: "Jerry", Age:21,sex: "Boy"}  that is, if the following argument has the same name as the previous argument, then the previous parameter value will be overwritten.     3, Extend (BOOLEAN,DEST,SRC1,SRC2,SRC3 ...)   The first parameter Boolean represents whether to make a deep copy, and the remaining parameters are consistent with the previous description   For example   code as follows: Var result=$.extend (True, {},  {name: "John", Loca tion: {City: "Boston", County: "The USA"}},  {last: "Resig", Location: {state: "MA", County: ""});    we can To see that the nested SRC1 in the location:{city: "Boston"},SRC2 also has a nested object location:{state: "MA"}, and the first depth copy parameter is true, then the result of the merge is the:  code as follows: Result={name: "John", Last: "Resig", location:{city: "Boston", State:"MA", County: "China"}}    that is, it will also merge the nested subforms in SRC, and if the first argument Boolean is false, let's see what the result of the merge is, as follows:    code as follows : Var result=$.extend (false, {},  {name: "John", location:{city: "Boston", County: "USA"}},  {last: "Resig", L Ocation: {state: "MA", County: "" ";    then the result of the merge is:  code as follows: Result={name:" John ", Last:" Resig ", Location:{state: "MA", County: "}} "  

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.