>> Every module instance has a $DEFAULT export binding. Normally, it is
set to the module instance itself. `export = ?` overrides the value of
that binding. >> `import x from "y"` binds $DEFAULT in "y" to x. Maybe?
That would be how Node.js does. For those unfamiliar with how it works,
it's basically like this
var mod = { exports: {} };
(function(module, exports){
...
})(mod, mod.exports);
So if you assign things to the default exports like
exports.firstExport = value;
exports.secondExport = value;
You're assigning to the default provided export object. But since you also
have access to the container (module) you can opt to fully overwrite it
module.exports = singleExportedThing;
If you added things to exports and then overwrote module.exports with a new
value, those initial exports will not be visible as exports because the
original export object is overwritten.
exports.willBeOverwritten = true;
module.exports = singleExportedThing;
So the single export route is opt-in, but it's opted into in the large
majority of cases.
On Thu, Dec 6, 2012 at 11:54 AM, Kevin Smith <[email protected]> wrote:
>
> Note, however, that you still assume some hack in the semantics with
>> the "if it exists" part. To avoid that, you need to divorce the import
>> syntax from the naming-an-external-module syntax -- which I'd actually
>> prefer anyway, and which was the case in the previous version of the
>> proposal.
>>
>
> Could we eliminate the hack on the export side instead?
>
> Every module instance has a $DEFAULT export binding. Normally, it is set
> to the module instance itself. `export = ?` overrides the value of that
> binding. `import x from "y"` binds $DEFAULT in "y" to x. Maybe?
>
> - Kevin
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss