Managing JS objects while preserving references Scenario

I have foo:

{
    name: 'Mr. Foo',
    value: 4
}


I receive bar from the server:

{
    name: 'Mrs. Bar',
    description: 'Wife of Mr. Bar'
}


I wish to update foo to be identical to bar (containing only the same properties and values in bar, and nothing more), but I need every reference to now know about these new values. This means doing foo = bar won't work because anything that had a reference to foo still has reference to foo's original values and will keep just looking at those.

Possible Solution

I have been using angular.extend() in the cases that I know for a fact the properties will always be the same, but if I do that in this scenario, foo will wind up with name, value, and description properties, when I need only name and description.

I came up with the following "replacement" function as a part of a utility service designed to solve this problem, but I'm wondering if there's a more elegant way to do this (something that perhaps looks less prone to obscure bugs than this does).

replaceObj: function (obj, updates) {
    if (obj &amp;&amp; !Array.isArray(obj)) {
        // Extend original object
        angular.extend(obj, updates);

        // Get object keys
        var objKeys = Object.keys(obj);
        var updatesKeys = Object.keys(updates);

        // Delete original object properties that are not included in the updates object
        objKeys.forEach(function(objKey) {
            if (updatesKeys.indexOf(objKey) === -1)
                delete obj[objKey];
        });
    } else {
        console.error('utility.replaceObj called without valid parameters.');
    }
}
Instead of checking each property in the result to see whether it was in the source object, simply delete all of the properties in the destination object and then use angular.extend or Object.assign to copy from the source.

function replaceObj(target, source) {
    Object.keys(target).forEach(function(key) {
        delete target[key];
    });
    Object.assign(target, source);
}


Also, if you do want to check whether a property is in an object, using updates.kasOwnProperty(objKey) is more straightforward than making a separate array of keys and using indexOf.