Is there a cleaner way of setting the values a
,b
, and c
in bar
. Something similar to ES6 destructuring-assignment syntax?
bar = { foo: 10, a: 0, b: 0, c: 0, baz: 14 };
myFunc = (myObj) => {
const { foo } = myObj;
let a, b, c;
a = 1 + foo;
b = 2 + foo;
c = 3 + foo;
myObj.a = a;
myObj.b = b;
myObj.c = c;
}
myFunc(bar);
Assuming that bar
has already been instantiated somewhere else, I'd like to set the new values without creating/assigning a new object to bar
. We could do something like this myObj = {...myObj, a, b, c}
, but that'd assign a new object to bar
, from my understanding.