class foo {
constructor(req) {
this.req = req;
}
async bar() {
this.req.baz = {};
return 1;
}
}
const req = {};
req.baz.boof = await new foo(req).bar();
I would have thought that JS would eval the right hand side first and req.baz would be an object before the assignment of req.baz.boof was attempted. Yet I get an error saying that boof cannot be assigned because req.baz is undefined. I know the code is terrible and should be refactored. What fixes it is this:
const temp = await new foo(req).bar();
req.baz.boof = temp;
Has anyone seen this before? Is this the best workaround, assuming I can't refactor all the related code?