A question about module/imports/exports

Andreas Rossberg rossberg at google.com
Mon Aug 27 02:55:23 PDT 2012


On 27 August 2012 11:46, Shijun He <hax.sfo at gmail.com> wrote:
> On Mon, Aug 27, 2012 at 2:11 PM, Luke Hoban <lukeh at microsoft.com> wrote:
>>> And is there any difference if module A is write as:
>>
>>> module A {
>>>   var _a = 'a'
>>>   export function changeA(v) {
>>>      a = v
>>>   }
>>>   export {a: _a}
>>> }
>>
>> This should not work.  There is no value in scope inside the module 'A' with the name 'a' here.  The exported name 'a' is only available as a member of the module 'A' via 'A.a'.
>>
>
> Sorry I don't get it. Do you mean
>
> import {a} in A // compile error?
>
> but
>
> A.a // accessible?

No, Luke just meant that the assignment in changeA should read

  _a = v

since that is the local name of the variable. After changing that, the
module is indeed equivalent to the other version.

/Andreas


More information about the es-discuss mailing list