我想要更新一个对象,它可能长这样:
currentObject = {
someValue : "value",
myObject : {
attribute1 : "foo",
attribute2 : "bar"
}
};
使用包含一些更改的对象,例如:
updateObject = {
myObject : {
attribute2 : "hello world"
}
};
最后,我希望currentObject被更新,以便:
currentObject.myObject.attribute2 == "hello world"
那应该也可以对其他对象实现。
作为解决方案,我考虑遍历对象并以某种方式处理名称空间。但我想知道是否可以使用类似jQuery或Prototype的库轻松解决这个问题。
$.extend
应该可以满足你的需求。 - gen_Eric.extend
的相关内容:http://api.jquery.com/jQuery.extend/ - Ian