Home > Article > Web Front-end > Detailed usage of jQuery.extend function_jquery
Jquery's extension method extend is a commonly used method when we write plug-ins. This method has some overloaded prototypes. Here, let's learn about it together.
Jquery’s extension method prototype is:
extend(dest,src1,src2,src3...);
It means to merge src1, src2, src3... In dest, the return value is the merged dest. It can be seen that this method modifies the structure of dest after merging. If you want to get the merged result but don't want to modify the structure of dest, you can use it as follows:
var newSrc=$.extend({},src1,src2,src3...)//That is, change "{}" as dest parameter.
In this way, src1, src2, src3... can be merged, and then the merged result will be returned to newSrc. For example:
var result=$.extend({},{name:"Tom",age:21},{name:"Jerry",sex:"Boy"})
Then the merged result
result={name:"Jerry",age:21,sex:"Boy"}
That is to say, if the following parameter has the same name as the previous parameter, then the latter parameter will overwrite the previous parameter value. .
Maybe you already have some understanding of this function. Let’s look at another official jquery example (http://api.jquery.com/jQuery.extend/)
The code is as follows: