simple modules

Allen Wirfs-Brock Allen.Wirfs-Brock at
Thu Feb 4 14:23:43 PST 2010

Very nice...I really like the refactoring perspective. Essentially, there is a fairly simple refactoring transformation that can replace any sequence of top level ECMAScript code with a module. Basically, wrap it with a module declaration, add exports for any global declarations, add imports to any referenced "globals" (hmm...does the proposal have a way to do such an import), and add the necessary imports to the code that was left behind.

There probably are additional issues related to initialization order, but the basic concept is should be quite clear.


> -----Original Message-----
> From: es-discuss-bounces at [mailto:es-discuss-
> bounces at] On Behalf Of Sam Tobin-Hochstadt
> I want to give a little bit different answer to this, while still
> agreeing with Brendan and Allen.
> Shared state is important because in a language with state, you want
> to be able to divide your program up into modules without changing its
> behavior.  If you have a stateful piece of code, and you move it into
> its own module, that shouldn't change things any more than any other
> refactoring.  If you need to repeatedly create fresh state, ES
> provides nice mechanisms for that as well.  Similarly, if you have one
> module that imports A, and you divide it into two, both of which now
> import A, that refactoring shouldn't change how your program works.
> So rather than a fundamental CS reason, the decision is based in the
> desire to support the way we think people will want to program.
> Obviously, we might be wrong about that, but that's how I see it.
> --
> sam th
> samth at
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list