我需要能够在运行时合并两个(非常简单的)JavaScript对象.例如,我想:
var obj1 = { food: 'pizza', car: 'ford' }
var obj2 = { animal: 'dog' }
obj1.merge(obj2);
//obj1 now has three properties: food, car, and animal
Run Code Online (Sandbox Code Playgroud)
有没有人有这个脚本或知道内置的方法来做到这一点?我不需要递归,我不需要合并函数,只需要平面对象上的方法.