I should also say that I agree with you that it is unfortunate that if getFoo() is a function returning either a number or undefined (say), you can't use the proposed if(let) syntax to distinguish undefined.
On 4 December 2013 11:16, Nick Krempel <[email protected]> wrote: > Taking it further, a (probably controversial) suggestion would be to allow > "let" and "const" to be expressions, enabling: > > ```js > if ((let foo = getFoo()).isReady()) { > // foo in scope > } else { > // foo in scope > } > // foo not in scope > ``` > > There would be some details about whether its value is a Reference and > what to do with "let a = 1, b = 2" but probably the biggest issue would be > parsing ambiguities? > > Or in a different direction, could consider allowing ToBoolean conversions > for objects to be overloaded. > > Even without either of the two additions proposed above, I would still > find the if/switch/while(let) construct useful. For example, often a value > is known to be either an object or null (or undefined). (And if it had the > value 0 due to a bug in my program, it's not clear whether I want the true > branch or the false branch anyway: so I should just use an assert if I want > to protect against this.) > > Nick > > > > On 4 December 2013 10:38, Andreas Rossberg <[email protected]> wrote: > >> On 4 December 2013 11:14, Brendan Eich <[email protected]> wrote: >> > I took him to mean "please support const or let" - for sure! :-) >> >> To voice the con side, I'm not fond of binders in conditions because >> they depend on -- and thus encourage overuse of -- falsy/truthy values >> or other implicit-conversion-like techniques (and their metastasis in >> APIs). I have seen that harm overall clarity more than it helps, at >> least in C++. >> >> /Andreas >> _______________________________________________ >> es-discuss mailing list >> [email protected] >> https://mail.mozilla.org/listinfo/es-discuss >> > >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

