ES6 modules (sorry...)
Axel Rauschmayer
axel at rauschma.de
Sun Jun 15 20:32:54 PDT 2014
I apologize for this email, but I still don’t understand the current module design.
**Multi-export modules.** Modules made sense to me as long as they were maps from names to exported values:
```js
// Module 'library'
export function foo() {
}
export function bar() {
}
// Module 'client1'
import { foo, bar } from 'library';
foo();
bar();
// Module 'client2'
import lib from 'library';
lib.foo();
lib.bar();
```
Compared to CommonJS, the syntax is nicer and less redundant. Additionally, the curly braces for getting stuff out of a module work, because they look like destructuring. And you get load-time errors if imports don’t match exports.
**Single-export modules.** Still missing is support for single-export modules, which could be added as follows (the keyword `default` instead of the asterisk works just as well, in my opinion).
```js
// Module 'MyClass'
export* class {
};
// Module 'client3'
import* MyClass from 'MyClass';
```
At the moment, it seems to me like multi-export modules and single-export modules are mixed in a way that makes things difficult to understand.
Axel
--
Dr. Axel Rauschmayer
axel at rauschma.de
rauschma.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140615/33caddf6/attachment.html>
More information about the es-discuss
mailing list