Instead of do-blocks you can use labelled blocks:
```js
myBlock: {
let foo = ...;
}```
This is nothing more than a label before a block. What is neat about this
is that break works inside the block, so:
```js
var myGlobal = 5;
myBlock: {
let foo = Math.random();
if(foo<0.5) break myBlock;
myGlobal = 10;
}
console.log(myGlobal); //50% of the times it will be 5, 50% of the times it
will be 10.
```
This all works today (except for the let declaration), so not sure if
anything is needed to replace this.
Marius Gundersen
On Mon, Nov 4, 2013 at 12:36 PM, Axel Rauschmayer <[email protected]> wrote:
> What is the best way to create top-level scopes in ES6?
>
> This isn’t possible, any more, right (given that nested module won’t be in
> ES6)?
>
> ```js
> module {
> let foo = ...;
> }
> ```
>
> Then we are left with:
>
> ```js
> {
> 'use strict';
> let foo = ...;
> }
> ```
>
> On the other hand, it would be nice to have `do { ... }` blocks (of which
> I don’t know the current status), which would eliminate the remaining use
> case for IIFEs. With do blocks, the above would become shorter:
>
> ```js
> do {
> let foo = ...;
> }
> ```
>
> It may make sense to terminate this expression statement with a semicolon.
>
> Axel
>
> --
> Dr. Axel Rauschmayer
> [email protected]
>
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
>
>
>
>
> _______________________________________________
> 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