The global object should not be the "global scope instance object"

Andreas Rossberg rossberg at google.com
Fri Jan 27 00:07:52 PST 2012


On 26 January 2012 23:31, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> On Jan 26, 2012, at 11:26 AM, Andreas Rossberg wrote:
>> Module scoping is difficult, especially if you want a semantics that
>> can be decided efficiently. Moreover, shadowing and recursion (and
>> every ES6 scope is recursive) don't go together well. And things get
>> even more interesting with "import *".
>
> Can you give an example of what you mean by "recursive" in this context? Do you mean that a scope can contain references to bindings defined by the scope?

Yes, every binding sees every other binding in the same scope
(including itself). It is not clear to me how that can be combined
with intra-scope shadowing. Which instance of a name would be visible
where in the same scope?

There are many programming languages that allow shadowing in the same
scope, and quite a few that have recursive scopes. But I don't know
any that would have both. I believe it's asking for trouble.


>> You might get away with duplicate imports in separate scripts, like in
>> your example. But AFAICS, that essentially amounts to reintroducing
>> the multiple-scripts-as-nested-scopes idea through the backdoor. Just
>> consider that in the presence of import shadowing, you could rewrite
>>
>>  let x = e
>>
>> to
>>
>>  module __fresh_name__ { export let x = e }
>>  import {x} from __fresh_name__
>>
>> and thereby have the same effect as if shadowing was allowed for let.
>
> Huh?
>
> <script>
> module _fn_ {export let x = e}
> import {x} from _fn_
> </script>
> <script>
> import {x} from _fn_
> </script>
>
> seems quite different from
>
> <script>
> let x=e;
> </script>
> <script>
> let x=e;
> </script>

Not if you rewrite each let separately. That gives:

<script>
module _fn1_ {export let x = e}
import {x} from _fn1_
</script>
<script>
module _fn2_ {export let x = e}
import {x} from _fn2_
</script>

And you have two different instances of x, one shadowing the other.

/Andreas


More information about the es-discuss mailing list