// merge two object, modifying the first; var object1={ apple:0, banana:{weight:14,price:233}, cherry:97 }; var object2={ banana:{price:333}, cherry:38 }; jquery.extend(object1,object2); //result: object1={apple:0,banana{price:333},cherry:38} //Example: Merge two objects recursively, modifying the first var object1 = { apple: 0, banana: {weight: 52, price: 100}, cherry: 97 }; var object2 = { banana: {price: 200}, durian: 100 };
$.extend(true, object1, object2); //result: object1 === {apple: 0, banana: {weight: 52, price: 200}, cherry: 97, duria //Example: Merge defaults and options, //without modifying the defaults. This is a common plugin development pattern.