Ambiguity with default exports and live bindings?
Bergi
a.d.bergi at web.de
Wed Jul 6 23:38:38 UTC 2016
/#!/JoePea schrieb:
> Is it true one of the following does not create a live binding?
Yes and no.
> ```js
> let A = 123
> export default A // not a live binding?
> ```
Actually it does create a live binding - to the variable with the name
"*default*" which you cannot assign. But yes, the binding `A` is not
exported.
> ```js
> let A = 123
> export {A as default} // live binding?
> ```
Yes.
> If so, this seems like large source for unexpected behavior when people
> create modules. I can imagine people easily overlooking the difference and
> expecting live bindings in both cases (this already happened to me).
I think people do in general not expect live bindings at all. For
declarations and the purpose of initialisation order, yes, but not for
mutable variables. You should export `const`s.
See also
http://stackoverflow.com/q/35223111/1048572?what-is-the-difference-between-importing-a-function-expression-or-a-function-declaration-from-a-ES6-module.
Kind regards,
Bergi
More information about the es-discuss
mailing list