假设有两个对象
source = {
name: "A",
address: {
city: "B",
zipcode: "C"
},
car: {
make: "D",
model: "E"
}
};
target = {
name: "",
address: {
city: ""
}
};
现在我想将所有数据从源复制到目标。但是,如果目标中已经存在相应的属性,则必须进行复制。它类似于 jQuery 的扩展,没有添加新属性。有了上面的数据,结果将是......
target = {
name: "A",
address: {
city: "B"
}
};
如何轻松实现这一目标?