Create a Utility function that can expand objects, for example:
function extendObj(obj1, obj2){
for (var key in obj2){
if(obj2.hasOwnProperty(key)){
obj1[key] = obj2[key];
}
}
return obj1;
}
And then expand this object with foodother objects. Here is an example:
food = extendObj(food, a);
food = extendObj(food, b);
source
share