Update on ES3.1 block scoped function declarations

Brendan Eich brendan at mozilla.org
Thu Jul 10 13:45:01 PDT 2008


On Jul 10, 2008, at 1:28 PM, Mark S. Miller wrote:

> On Thu, Jul 10, 2008 at 11:05 AM, Brendan Eich  
> <brendan at mozilla.org> wrote:
>
> So what would this program print in ES3.1?
>
> const C = 42;
> function f(x, y) {
>   const C = 33;
>   if (x) {
>     const C = 21;
>     return eval(y);
>   }
>   return C;
> }
> print(f(true, "C"));
>
> 21
>
> What does it print in ES4-opt-in?

Call it ES4, please. There's no point in playing games about opt-in,  
since we know we can't "break the web". ES3 added new syntax, so did  
ES2. No one bugged out about "opt-in".

21 is the right answer, although reflecting lexical blocks into  
something eval can see is a big pain (we did this in Firefox 2). It's  
a lot of work just for block-scoped const. Sorry if I missed the  
discussion, but was restricting const to top level considered?

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.mozilla.org/pipermail/es-discuss/attachments/20080710/34331120/attachment-0002.html 


More information about the Es4-discuss mailing list