Javascript 更新并忽略目标中未定义的字段

Javascript update and ignore undefined fields in destination

我希望实质上更新一个大型 javascript 对象。然而,前端的各种工具添加了不必要的字段,在更新对象时应忽略这些字段。我正在使用 angular,但如有必要,我愿意使用 lodash/underscore。我只是希望能够更新现有对象,而无需添加放置在 UI.

中时注入的额外字段
var ob1 = {
    attr1: 'stuff',
    attr2: 'stuff'
};

var ob2 = {
    attr1: 'changedstuff',
    attr2: 'stuff',
    uiCrap: 'junk'
};

update(ob1, ob2);
// should result in 
// ob1 = { attr1: 'changedstuff', attr2: 'stuff };

有没有人知道是否有内置的 angular/javascript 功能?

使用extend()函数:

var ob = _.extend(ob1, _.pick(ob2, _.keys(ob1)));