ES Modules: suggestions for improvement

Jussi Kalliokoski jussi.kalliokoski at gmail.com
Wed Jun 27 11:21:15 PDT 2012


On Wed, Jun 27, 2012 at 9:02 PM, David Herman <dherman at mozilla.com> wrote:

> On Jun 27, 2012, at 11:00 AM, Jussi Kalliokoski wrote:
>
> On Wed, Jun 27, 2012 at 8:43 PM, David Herman <dherman at mozilla.com> wrote:
>
>>
>>
>> http://blog.safeshepherd.com/23/how-one-missing-var-ruined-our-launch/
>>
>
> I don't see how that's at all related to modules or how modules would have
> prevented this.
>
>
> Because we're talking about static checking of unbound variables within
> modules. A reference to or assignment to an unbound variable would result
> in an early error.
>
For this, if it's actually that convenient, I'd actually suggest another
> destructuring pattern, because it might be useful in general as well:
>
> let * = Math;
>
>
> This is dynamic scoping. The difference between import * and let * is that
> the former is statically scoped, and the latter is dynamically scoped.
>

I'm sorry, I'm not entirely sure what static scoping means in the context
of JavaScript. Could you clarify? Does it mean that it's only applicable in
the context of the current file, module, domain or something like that?
Does it mean that it can't be shadowed by the dynamic scope, for example:

import a from b;
var a = 'foo';

What is a? 'foo', error or something else?


> What about exported objects then? Are they immutable to clients as well?
> That would make this unusable for libraries that have a plugin system, such
> as jQuery.
>
>
> Of course not. You can export a mutable object if you want to. You can
> export whatever you want.
>

Good. I might as well clear another question I had, say I have

--
foo.js

module foo {
  exports bar = {}
}

--
foo-plugin.js

module foo at './foo.js';
export bar from foo;

bar.baz = "zen";

--
uses-foo.js

module foo at './foo.js';
// insert some way to load foo-plugin here
console.log(foo.bar.baz); // What should this be?


> Dave
>
>
Cheers,
Jussi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120627/8a0acbb0/attachment-0001.html>


More information about the es-discuss mailing list