3 ms·
> if your lambda function returns an object literal than you need to wrap it in a statement block with a return statement Or you can just parenthesise the obje
by EvilTerran 10y ago
> if your lambda function returns an object literal than you need to wrap it in a statement block with a return statement
Or you can just parenthesise the object literal:
>>> (x => ({ x }))(23)
Object { x=23 }
The grammatical ambiguity is unfortunate, sure, but the simplest work-around isn't so bad.
- ralfn 10y agoIf one forgets the (parentheses) you may or may not immediate or later can an error _somewhere_. It isn't about the workaround -- it's about all the subtle bugs it will introduce in the edge-cases, for example: f => () => {} f(); // undefined instead of empty object