module exports

Kevin Smith zenparsing at gmail.com
Fri Mar 14 08:04:40 PDT 2014


>
>
>
> Because it doesn't allow for the Assignment Expression form (specifically,
> function expressions) that developers expect to be able to write:
>
>   export default function() {}
>

The alternative here is:

    function MyThing() {}
    export { MyThing as default };

Which is more clear, more readable, and barely less ergonomic.  If you
*really* want the AssignmentExpression form, you've got to put the equals
in there.  I've said this before, but without the equals it looks too much
like a declaration:

    export default class C {}
    var c = new C(); // No C defined, WTF?

Node users don't elide the equals sign, do they?

    module.exports = whateva;

So why are we?

Equals aside, let's look at the cost/benefit ratio here:

- Benefit: a little less typing (at most one savings per module)
- Cost: more confusion and StackOverflow questions about default export
syntax.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140314/20a5979a/attachment.html>


More information about the es-discuss mailing list