Block lambda grammar: BlockArguments

Lasse Reichstein reichsteinatwork at gmail.com
Mon Jan 16 05:54:12 PST 2012


On Mon, Jan 16, 2012 at 2:14 PM, Herby Vojčík <herby at mailbox.sk> wrote:
> Thank you, it helped.
>
> It is the fact that in ES up till now, {} block were always delimited by a
> keyword (if/else is probably the only case when two blocks were present). So
> it is not a bad idea to retain it.

I believe it's perfectly valid to write blocks (for no particular
reason) without any keyword.
I.e.:
  function foo() {
    var x = 42;
    {
      var y = 10;
      print(x+y);
    }
    return x;
  }

Obviously it's useless, but it is valid.
You could add a label to the block if you want to actually use it for something:

   bar: {
      if (x == 10) { y = 10; break bar; }
      if (x == 20) { y = 0; break bar; }
      ...
  }

/L 'Bad examples are bad!'


More information about the es-discuss mailing list