This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14459|Reply: 0

[Jquery] jQuery.extend function in detail

[Copy link]
Posted on 9/29/2016 8:27:19 PM | | | |

JQuery's extend extension method:
      Jquery's extension method extend is a common method we use in the process of writing plugins, and there are some overload prototypes in this method, so let's learn about it together.
      1. The prototype of Jquery's extension method is:





      What it means is to add src1, src2, src3... merge into a dest and return the value of the merged dest, which shows that the structure of the dest has been modified after the method is merged. If you want to get the result of the merge but don't want to modify the structure of the dest, you can use the following:






      This allows you to set src1, src2, src3... Merge, and then return the merge result to newSrc. For example:




      Then the result after the merger





      This means that if the subsequent parameter has the same name as the previous parameter, the subsequent parameter will overwrite the value of the previous parameter.

      2. Omit the dest parameter
      If omitted, the method can only have one src parameter, and the src can be merged into the object that calls the extend method, such as:
1、$.extend(src)
This method is to merge src into the global object of jquery, such as:





It is to merge the hello method into the global object of jquery.
2、$.fn.extend(src)
This method merges src into the jquery instance object, such as:



It is to merge the hello method into the jquery instance object.

Here are a few examples of commonly used extensions:







This is an extension of a .NET namespace in a jquery global object.





    This is an extension of the hello method to the net namespace of Jquery, which was previously extended.

3. There is also an overload prototype in Jquery's extend method:  





      The first parameter boolean represents whether to make a deep copy, and the rest of the parameters are the same as those introduced earlier.





      We can see that the nested sub-object location:{city:"Boston"} is nested in src1, and the sub-object location:{state:"MA"} is also nested in src2, and the first depth copy parameter is true, then the merged result is:



       That is, it will merge the nested subobjects in the src as well, and if the first parameter boolean is false, let's see what the result of the merge is, as follows:





     The result of the merger is:



These are some details of how $.extend() is often used in projects.








Previous:highcharts pie chart drill down example
Next:Highcharts stacked histograms with drill-down functionality
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com