合并多个对象
$.extend(deep,target,object)
deep指示是否深度合并对象,默认为false。如果该值为true,且多个对象的某个同名属性也都是对象,则该"属性对象"的属性也将进行合并。,
var object1 = {
apple: 0,
banana: { weight: 52, price: 100 },
cherry: 97
};
var object2 = {
banana: { price: 200 },
durian: 100
};
// 将 object2 递归合并到 object1中
$.extend( true, object1, object2 );
结果:
object1: {"apple":0,"banana":{"weight":52,"price":200},"cherry":97,"durian":100}
$.extend( false, object1, object2 );
结果:
{"apple":0,"banana":{price:200},"cherry":97,,"durian":100}
网友评论