Assuming I have the following two objects
foo = {
a: 10
b: 'hello'
c: 'world'
}
bar = {
a:5
b: null
c: null
d: "This is not in foo"
}
I would like to have an operation which would do the equivalent of below operation but without having to specify it for each member.
bar.a ??= foo.a
bar.b ??= foo.b
bar.c ??= foo.c
console.log(bar) // {a:5, b:'hello', c:'world', d:'This is not in foo'
Essentially: For each member of bar, if it is nullish take the value in foo. Leave all members which exist in foo but not in bar in peace
How would I go about this? I have tried to search a solution using destructuring in some way but with no success...