Is the common use case for "export default" when you want to give users of the module an easy way to obtain a single function?
So instead of users doing this: import {someFn} from 'wherever'; they can do this: import someFn from 'wherever'; On Fri, Mar 14, 2014 at 9:40 AM, Rick Waldron <waldron.r...@gmail.com>wrote: > > > > On Fri, Mar 14, 2014 at 10:07 AM, Mark Volkmann <r.mark.volkm...@gmail.com > > wrote: > >> On Fri, Mar 14, 2014 at 8:54 AM, Kevin Smith <zenpars...@gmail.com>wrote: >> >>> >>>> I'm trying to understand how that compares to ES6 modules. I see how in >>>> ES6 I can import specific things from a module or I can import everything a >>>> module exports. >>>> >>> >>> You can't really import all exported bindings. You can import the >>> module instance object itself: >>> >>> module M from "wherever"; >>> >>> which will give you access to all of the exports. >>> >> >> That's what I meant by importing all the exports. >> I'd prefer it if the syntax for that was >> >> import M from "wherever"; >> > > As Kevin said, this already means "import the default export from > 'wherever'" > > >> >> That way I could think of import is doing something like destructuring >> where the other syntax below is just getting some of the exports. >> >> import {foo, bar} from "wherever"'; >> >> >>> >>> >>>> Am I correct that a "default" export can be somewhere in the middle ... >>>> a subset of everything that is exported? >>>> >>> >>> Not really. The default export is literally just an export named >>> "default". There is sugar on the import side, where you can leave off the >>> braces: >>> >>> import foo from "somewhere"; >>> >>> is equivalent to: >>> >>> import { default as foo } from "somewhere"; >>> >>> The specialized default export syntax is just plain confusing and should >>> be jettisoned, in my opinion. It would be less confusing for users to >>> simply write: >>> >>> export { foo as default }; >>> >>> I fail to see why sugar over this form is necessary. >>> >> > Because it doesn't allow for the Assignment Expression form (specifically, > function expressions) that developers expect to be able to write: > > export default function() {} > > Rick > -- R. Mark Volkmann Object Computing, Inc.
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss