Is this possible in javascript?
let a, b; // Both objects, eg vectors
let bl = false; // This is a bool that could be true or false
// Is this possible, or how could it be done
(bl ? a : b) = {x: 5, y: -2, z: 3};
Ie, I want to set either a or b to this vector conditionally depending on bl.
Or is the only way:
let tmp = {x: 5, y: -2, z: 3};
if(bl) a = tmp;
else b = tmp;
I just feel there should be a more elegant way of doing this.
>Solution :
Well in a way it is but it’s just a short hand of what you wrote as an alternative.
let a, b;
let bl = true;
let obj = {x: 5, y: -2, z: 3}
bl ? a = obj : b = obj;