(Almost) everything is expression
David Herman
dherman at mozilla.com
Fri Nov 11 09:13:54 PST 2011
On Nov 11, 2011, at 8:19 AM, Mark S. Miller wrote:
> On Fri, Nov 11, 2011 at 7:40 AM, gaz Heyes <gazheyes at gmail.com> wrote:
> On 11 November 2011 15:33, Mark S. Miller <erights at google.com> wrote:
> let a = ({
>
> print('doing stuff');
> 100;
> });
>
> How do you know the difference between a blank block statement and a object literal? Surely it becomes an expression once an assignment occurs anyway.
>
> Doh! Sorry, I completely mis-thought that. Nevermind.
Your idea of mandatory parens is still valid (if, IMO, a bit unsatisfyingly verbose) for most statement forms. It's only the block-statement-expression that doesn't work. Hence my do-expressions:
http://wiki.ecmascript.org/doku.php?id=strawman:do_expressions
or Brendan's subtly-disambiguated-block-statement-expressions:
http://wiki.ecmascript.org/doku.php?id=strawman:block_vs_object_literal
If Brendan's idea can be made to work, and it's not too confusing, I'm pretty sure I'd prefer it over do-expressions. You could simply write:
let a = {
print('doing stuff');
100
};
How gorgeous is that?
But I suspect as we work on evolving the syntax of object literals, it'll get harder to keep them disambiguated. For example, is this:
let a = {
foo(x)
{
alert(x)
}
}
...equivalent to this?
let a = {
foo: function(x)
{
alert(x);
}
};
...or this?
let a = {
foo(x);
{
alert(x);
}
};
So I just don't know if it's feasible.
Dave
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111111/1140528b/attachment-0001.html>
More information about the es-discuss
mailing list