[Original]
1. Extend the jquery static method.
1 $. Extend ({
2 Test: Function () {Alert ( ' Test function ' )}
3 })
Usage: $. Test ()
2. Merge multiple objects.
For jquery. Extend (css1, css2), css1 and css2 have some attributes.
The extend function adds the attributes of css2 but not of css1 to css1. If a property of css2 and a property name of css1 are used, the attributes of css2 are used to overwrite the attributes of CSS 1 with the same name. Css1 is the final sum object. Or you can use:
VaR newcss = jquery. Extend (css1, css2) newcss is the new object to be merged.
VaR newcss = jquery. Extend ({}, css1, css2) newcss is the new object to be merged, and does not destroy the structure of css1.
Code
1 // Usage: jquery. Extend (obj1, obj2, obj3 ,..)
2 VaR Css1 = {Size: " 10px " , Style: " Oblique " }
3 VaR Css2 = {Size: " 12px " , Style: " Oblique " , Weight: " Bolder " }
4 $. Jquery. Extend (css1, css2)
5 // Result: The size attribute of css1 is overwritten and inherits the weight attribute of css2.
6 // Css1 = {size: "12px", style: "oblique", weight: "Bolder "}
7
3. Deep set object
The new extend () allows you to more deeply combine inlaid objects. The example below is a good proof.
Code
1 // Previous. Extend ()
2 Jquery. Extend (
3 {Name: "John", Location: {City: "Boston "}},
4 {Last: "resig", Location: {state: "Ma "}}
5 );
6 // Result:
7 // ==>{ Name: "John", last: "resig", Location: {state: "Ma "}}
8 // New more in-depth. Extend ()
9 Jquery. Extend ( True ,
10 {Name: "John", Location: {City: "Boston "}},
11 {Last: "resig", Location: {state: "Ma "}}
12 );
13 // Result
14 // ==>{ Name: "John", last: "resig ",
15 // Location: {City: "Boston", state: "Ma "}}
16