The idea, not a valid code, inspired by this answer:
const source1 = {x1: -5, y1: -5, x2: 10, y2: 10};
const source2 = {x1: 15, y1: 15, x2: 20, y2: 20};
// the ['s1x1'] expression becomes the variable name and x1 as its value
const [['s1x1']: x1, ['s1y1']: y1, ['s1x1']: x2, ['s1x1']: y2] = source1;
const [['s2x1']: x1, ['s2y1']: y1, ['s2x2']: x2, ['s2y2']: y2] = source2;
// use the new variables
let result = s1x1 * s2x1;
Questions
- Is there a way to to deconstruct object into custom named variables?
- Does it make sense in terms of performance?