See http://wiki.ecmascript.org/doku.php?id=strawman:default_operator --
the proposal there is ?? and ??= since single ? is ambiguous after an
expression due to conditional expressions (?:).
The "default operator" doesn't address a significant part of what Dmitry is
asking for -- the . in the ?. usage -- which allows the property access to
be expressed only once and used for both the test and assignment.
let street = user.address?.street
which desugars e.g. into:
street = (typeof user.address != "undefined" && user.address != null)
? user.address.street
: undefined;
Part of what Dmitry asked for, I'd like to see in the plain ?: operator, and
it seems like it would be possible to disambiguate from a top-down parser
perspective. I would like to see the `:` ("else condition") portion of a ?:
expression be optional. For instance:
var a = b ? c; // aka, `var a = b ? c : undefined`
The other (more awkward/obscure looking) way to do this is:
var a;
b && a = c;
The difference between the sytnax sugar I'm asking for and the "default
operator" in the strawman is that ?: (or &&) allows for separate expressions
for the test (`b`) and the success_value (`c`), whereas ?? requires that the
test expression and success_value be the same expression.
For instance:
var a = (b > 5) ? b : undefined;
In this case, the ?? "default operator" is of no use. But being able to drop
the `: undefined` part, and also avoid using the more awkward looking &&
syntax, would certainly be a useful sugar.
--Kyle
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss