var object1 = { apple: 0, banana: {weight: 52, price: 100}, cherry: 97 }; var object2 = { banana: {price: 200}, durian: 100 };
将object2 合并到 object1 中
1.jquery用法:
$.extend(object1, object2);
console.log(object1); //{apple: 0, banana: {price: 200}, cherry: 97, durian: 100}
2.ES6用法: Object.assign(object1, object2);
console.log(object1); //{apple: 0, banana: {price: 200}, cherry: 97, durian: 100}