4 ms·
Shameless plug, I introduced an ECMA proposal for a conditional rest and spread operator a few months ago and would appreciate support or suggestions if you wou
by aiddun 4y ago
Shameless plug, I introduced an ECMA proposal for a conditional rest and spread operator a few months ago and would appreciate support or suggestions if you would find it useful.
https://es.discourse.group/t/conditionally-add-elements-to-declaratively-defined-arrays/1041 https://es.discourse.group/t/conditionally-add-elements-to-d...
- wruza 4y agoNot sure about the proposed form, but having proper expression-only ifs in arrays and objects would be nice. Including the spread syntax. [ "foo”, if (cond1) bar, if (cond2) ...baz, ] Pretty sure it was already proposed and rejected, but still.
- archduck 4y agoThis ain’t pretty, but it works: [ “foo”, ...(cond1 ? [bar] : []), ...(cond2 ? baz : []), ] --- Edit: note to self: read the link before commenting.
- somishere 4y agoNice one. I run into this regularly, and it always leads to some kind of nullish spread spaghetti. I really like the idea of an empty / non-value operator that works on objects, arguments & iterables. Q - is it just a matter of liking posts on tc39 discourse to show support?