Hi Isaac,
I share some of your concerns as well. I like the idea of "import" just
returning an object, which can be destructured using let. I also like the
idea of eliminating the "import *" syntax. However, I think that dynamic
exports ("export <expression>") might not be as useful as it seems.
In my modules, I use the "export <expression>" form for the following
reasons:
1. When I want to export a single function (perhaps a constructor), and I
don't want importers to unnecessarily repeat the function name:
var MyClass = require("MyClass").MyClass; // Boo!
var MyClass = require("MyClass"); // Better!
2. When I want to rename an export:
function shortName() { ... }
module.exports = { longName: shortName };
3. When I want to group together the exported API, instead of having it
spread across the file:
function A() { ... }
function B() { ... }
function C() { ... }
module.exports = { A: A, B: B, C: C };
For case 1, destructuring allows us to eliminate the repetition:
let { MyClass } = import "MyClass.js";
A static multiple export syntax ("export { ... }") would work just fine for
cases 2 and 3:
export {
longName: shortName,
A,
B,
C
};
Are there any other cases where dynamic exports are useful?
- Kevin
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss