I assume you mean m.load("la1").
So what is the behavior if you do new m.load("la1").Foo() if you know Foo is an 
exported object? Is there a module API that allows one to introspect a modules 
content?



On Jan 26, 2011, at 1:46 PM, Sam Tobin-Hochstadt <[email protected]> wrote:

> On Wed, Jan 26, 2011 at 2:04 PM, James Burke <[email protected]> wrote:
>> CommonJS Modules 1.1 allows this kind of construct in module code:
>> 
>> var a;
>> if (someCondition) {
>>    a = require("a1");
>> } else {
>>    a = require("a2");
>> }
>> 
>> and the module "a1" is not actually evaluated until execution reaches
>> the a = require("a1") call.
>> 
>> 1) Could something like this work in Simple Modules? If so, what would
>> be the syntax for it?
> 
> You can use module loaders to do exactly this (I believe, based on my
> understanding of CommonJS).  It would look like:
> 
> var ml = ... the desired module loader ...
> var a;
> if (someCondition) {
>  a = ml.load("a1");
> } else {
>  a = ml.load("a2");
> }
> 
> This produces a module instance object, bound to |a|.  It doesn't,
> however, allow you to import from |a|, since nothing is statically
> known about what the exports of |a| are.
> 
>> 2) What are the design decisions behind only allowing "module" and
>> "use" at the top level of a module?
> 
> Modules are a statically scoped construct, and the implementation and
> the programmer can both statically tell where variables come from.
> This prevents modules from being dynamically created, except in the
> context of module loaders, as seen above.
> -- 
> sam th
> [email protected]
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to