Here is a dummy example:
const obj = {foo: '123'};
function logObj(obj) {
setInterval(function() {
console.log(obj);
}, 100)
}
function overWrite(obj) {
setTimeout(function(){
console.log('overwriting')
obj = {foo: 'bar'}
}, 1000);
}
logObj(obj)
overWrite(obj)
I'm expecting to see { foo: '123' }
every 100ms until overwriting
is called and then to see { foo: 'bar' }
. However the object is never over-written and I always see 123.
EDIT
I do not want to change just one of the keys; I do in fact want to replace the entire object, so doing obj.foo = 'bar'
is not a solution