Remarks about module import

Ingvar von Schoultz ingvar-v-s at comhem.se
Tue Aug 19 01:00:44 PDT 2008


ihab.awad at gmail.com wrote:
> An importer could use this as follows --
> 
>   var doc = ...;
>   var bg = ...;
> 
>   import
>       of fetchModule('http://foo.com/someModule.js'),
>       with document: doc, background: bg
>       using t: toggle, s: set;

 From the descriptions it looks like this could instead use
a syntax based on destructuring assignment, if es-harmony
will have destructuring:

     var {toggle: t, set: s} = import
     (   fetchModule ('http://foo.com/someModule.js'),
         {document: doc, background: bg}
     );
     t();

One advantage would be that people would remember this syntax
easily, since it's useful elsewhere.

As a side effect, one could then choose to use the returned
object instead:

     var m = import
     (   fetchModule ('http://foo.com/someModule.js'),
         {document: doc, background: bg}
     );
     m.toggle();

-- 
Ingvar von Schoultz



More information about the Es-discuss mailing list