Modules, Concatenation, and Better Solutions

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Tue Oct 16 06:08:12 PDT 2012


Just to be sure... Does a get printed only the first time the module A is
imported somewhere, or every time?

On Tue, Oct 16, 2012 at 3:57 PM, Patrick Mueller <pmuellr at yahoo.com> wrote:

> On Mon, Oct 15, 2012 at 9:45 AM, Kevin Smith <khs4473 at gmail.com> wrote:
>
>> OK, so:
>>
>>     module A { console.log("a"); export var x; }
>>     console.log("$");
>>     import x from A;
>>
>> Does this print:
>>     $
>>     a
>> or
>>     a
>>     $
>>
>
> The first - "$", then "a".
>
> At least, that's how most module systems I've played with seem to work -
> CommonJS-ish ones I've written and used, and mostly AMD; there was an issue
> with the AMD almond loader that it would execute a "module factory" when
> the module was define()'d, not when it was first require()'d.  Can't
> remember the final stand on that one.  I think most of the AMD loaders will
> ensure that factories are not run until needed.
>
> This has worked out quite well, as it means ordering of modules doesn't
> matter - Browserify is a good example of this.  It means you don't HAVE to
> arrange your modules in any particular order, just make sure they are all
> defined before you do your first require().  MUCH, MUCH easier to build
> concatenators if you don't care what the order is.
>
> --
> Patrick Mueller
> pmuellr at gmail.com
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121016/eb9dd8c8/attachment.html>


More information about the es-discuss mailing list