simple modules

Kevin Curtis kevinc1846 at
Thu Feb 4 15:35:03 PST 2010

On Thu, Feb 4, 2010 at 9:25 PM, Sam Tobin-Hochstadt <samth at>wrote:

> 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.
Great stuff - really clarifies things.
I understand simple_module's as being like python modules or Delphi units or
C #include (with a 1 to 1 relation between the .h, .c files).
It should be possible to take seperate .js source files - with module
{...}'s - and put them into one source file and the Program behaves the
If a developer wants multiple instances of state - use objects or closures.
This (for me) requires a bit of reorientation from the 'modules are (frozen)
objects returned from function closures which contain the modules private
state' pattern.

Interesting to see how modules work with native plaform functionality. It is
said 'modules don't confer authority - objects do'. But aren't modules in
someway authority bearing - even if indirectly via the objects they
namespace. (No reply needed - i should wait for the Context/Isolation
strawman - but this is what's on my mind :) ).

// Context/ModuleLoader A
-- one.js
import dom; // imports document
document.x = 1;

-- two.js
import dom; // imports document
alert(document.x); // shows 1

// Context/ModuleLoader B - no dom authority
-- three.js
import dom; // no authority - error

N.B the import of module dom could be implicit/automatic - if the Context
has 'authority' to the module.
inter-Context communication - JSON only?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list