The Extend extension method prototype in jquery is:
1, Extend (dest,src1,src2,src3 ...);
It means 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 results of a merge but do not want to modify the structure of the dest, you can use the following:
2, Var newsrc=$.extend ({},src1,src2,src3 ...) That is, "{}" as the Dest parameter.
This can be src1,src2,src3 ... To merge, and then return the merge results to NEWSRC.
The following example:
Copy Code code as follows:
var result=$.extend ({},{name: "Tom", Age:21},{name: "Jerry", Sex: "Boy"})
Then the combined results
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 argument Boolean represents whether to make a deep copy, and the rest of the parameters are consistent with the previous
For example
Copy Code code as follows:
var Result=$.extend (True, {},
{Name: "John", Location: {City: "Boston", County: "USA"}},
{Last: "Resig", Location: {state: "MA", County: "" "});
We can see that the nested SRC1 in the location:{city: "Boston"},SRC2 also have nested objects location:{state: "MA"}, the first depth copy parameter is true, then the result of the merge is:
Copy Code code as follows:
Result={name: "John", Last: "Resig", location:{city: "Boston", State: "MA", County: "The"
That is, it merges the nested subforms in SRC, and if the first argument is false, let's see what the result of the merge looks like:
Copy Code code as follows:
var result=$.extend (False, {},
{Name: "John", location:{city: "Boston", County: "USA"},
{Last: "Resig", Location: {state: "MA", County: "" "});
Then the result of the merger is:
Copy Code code as follows:
Result={name: "John", Last: "Resig", Location:{state: "MA", County: "Our"}