Do Anonymous Exports Solve the Backwards Compatibility Problem?

David Herman dherman at
Wed Dec 19 16:09:21 PST 2012

On Dec 19, 2012, at 3:22 PM, David Herman <dherman at> wrote:

> On Dec 19, 2012, at 12:05 PM, Andreas Rossberg <rossberg at> wrote:
>>> Assigning a single exports also nudges people to make small modules
>>> that do one thing.
>> It rather nudges people into exporting an object as a module, instead of writing a real module. The only "benefit" of that is that they lose all static checking.
> I don't think that's fair. It's just an anonymous export. The contents of an export are always dynamic.
> All this "nudge" stuff makes me itch, though. I have about ε sympathy for enforcing/encouraging aesthetics and styles. That ain't JavaScript's way, and I sure don't trust TC39 (i.e., me) to take on a paternalistic role.

Chatted with James and realized I wasn't clear here.

What I mean is, I don't believe that we should be making decisions based on how we will cause people to have good (or our preferred) style. I don't think we know how to make those kinds of predictions, and at least in this particular issue I'm skeptical that it actually works. Regardless of cowpaths, we don't exactly have empirical data on whether any particular aspect of the design influences people's design of their libraries. I'm not comfortable with a decision resting on that.

Instead, I've found the most persuasive argument so far to be that a module that encapsulates a single abstraction -- which is a common phenomenon in basically every language ever -- typically wants to name the abstraction and the module with the same name, and you'd like to be able to elide the two somehow.

OTOH, `export =` *still* doesn't provide all the conveniences that you get from Node. In particular, contrast:

    var x = require('quux').foo().bar().baz().yippee();


    import 'quux' as quux;
    var x =;

This is why Isaac wanted an expression form, like:

    var x = (import 'quux').foo().bar().baz().yippee();

I'm warm to the expression form. It's completely compatible with declarative exports; (import 'quux') is simply a shorthand for a declarative import-as followed by a reference to the module name. It does have a cost for compilation time, though, since the compiler can't just scan the AST shallowly for imports at top-level.


More information about the es-discuss mailing list