ES6 modules (sorry...)

Rick Waldron waldron.rick at gmail.com
Mon Jun 16 11:14:58 PDT 2014


A few more thoughts...


On Mon, Jun 16, 2014 at 1:41 PM, Jasper St. Pierre <jstpierre at mecheye.net>
wrote:

>
> On Mon, Jun 16, 2014 at 1:22 PM, Rick Waldron <waldron.rick at gmail.com>
> wrote:
>
>>
>> On Mon, Jun 16, 2014 at 1:05 PM, Calvin Metcalf <calvin.metcalf at gmail.com
>> > wrote:
>>
>>> e.g. something like
>>> https://gist.github.com/calvinmetcalf/9252f41bf6e3c8b4add7
>>>
>>
>> re:
>>
>>   let { foo, bar } = import "library";
>>
>> Ignoring the UnaryExpression ambiguity, what happens here:
>>
>>
>> // library.js
>> export const MAX_VALUE = 1023;
>>
>>
>> // program.js
>> let { MAX_VALUE } = import "library";
>> MAX_VALUE = 1;
>>
>
> Seems like a straightforward thing to me. "let" creates a local binding
> for the scope of the file. It shouldn't be anything different from:
>
>     function importMyLibrary() {
>         let module = import "library";
>

When does the actual import operation take place? Can I assume that it
takes place only after `importMyLibrary` is called? If so, then `import`
will block while awaiting IO—this is "maybe" ok for non-browser JS
runtimes, but not ok for the browser.


>         return module;
>     }
>
>     let { MAX_VALUE } = importMyLibrary();
>     MAX_VALUE = 1;
>
> Or:
>
>     function importMyLibrary() {
>         let module = import "library";
>         let MAX_VALUE = module.MAX_VALUE;
>         return { MAX_VALUE: MAX_VALUE };
>     }
>

Yes that reassignment works, but it would be a serious flaw (potentially a
security hazard) if the language just assumed that was was the desired
behaviour.

Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140616/bab082d1/attachment.html>


More information about the es-discuss mailing list