Boolean shortcuts

François REMY fremycompany_pub at
Wed Jan 4 13:50:26 PST 2012

“You already have to.” –> If something is bad, don't change it?

(1) Block expressions are not useful because you can't use them as expressions (=retreive their value) if you don't use “string eval”.
(2) Object syntax is restricted because lookahead comes at a cost for parsers. 

This is a mess. Beginners hate it. Parsers don't like it. And yet it's still there...

Personnaly, I would like to do something like that (and I remind an earlier proposal from the mailing list) :

    // try to create an "x" variable
    let x = try { doSomething() } catch (ex) {};


    // log the value of 1+2+3+...+10
    console.log (eval { let i=10, j=0; while(i) { j+=i—; } });

Now, I have to do something like that :

    // not as readable
    let x; try { x=doSomething() } catch (ex) {}


    // bad but close in term of input
    console.log(eval("let i=10, j=0; while(i) { j+=i--; }"));

    // as optimized, but not as readable
    { let i=10; let j=0; while(i) { j+=i--; }; console.log(j); };

The introduction of the “eval” keyword before a block has tons of other advantages : 

    {}.toString(); // will now compile and return “[object Object]” from anywhere in the code 

That means I can do something like :

    let props = eval {
        let obj   = func();
        let prop1 = getProp1(obj);
        let prop2 = getProp2(obj, prop1);
            prop1: prop1, 
            prop2: prop2

Another proposed syntax, namely

    this.function() {} <—> (function() {}).bind(this)

will now be acceptable since

    function() {
        return this.function(); //ASI

is not allowed in ES6, there’s no syntax conflict. So, we can introduce the [noLineBreak] token after “function” safely.

BTW, I also think we should drop labels for ES6. This will help to simplify syntax, too. With ES6, we should build a new syntax that’s more logical to use.

-----Message d'origine----- 
From: Mike Samuel 
Sent: Wednesday, January 04, 2012 9:17 PM 
To: Herby Vojčík 
Cc: François REMY ; es-discuss at 
Subject: Re: Boolean shortcuts 

2012/1/4 Herby Vojčík <herby at>:
> Hi,
> If you must think whether you should put it in
> parentheses or not to prevent runtime error, you rather write { window:false
> } and reduce the insecurity.

You already have to.

'boolean' === typeof eval('{ window: false }')

See section 12.4  :
12.4 Expression Statement # Ⓣ
ExpressionStatement :
[lookahead ∉ {{, function}] Expression ;

NOTE An ExpressionStatement cannot start with an opening curly brace
because that might make it ambiguous with a Block.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wlEmoticon-smile[1].png
Type: image/png
Size: 1041 bytes
Desc: not available
URL: <>

More information about the es-discuss mailing list