domenic at domenicdenicola.com (2014-04-15T15:46:54.472Z)
What's the history of the unused keyword "package", is it from Java?
Been thinking about this lately, could an external module be called a package?
```
package/file.js
package "something" {
export class foo {}
}
package "other" {
export class foo {}
export module bar {
export class foo {}
}
}
import {foo as a} from "something"
import {foo as b, bar.foo} from "other"
/* option a) */
var api = {
foo: a,
fooOther: b,
fooBar: bar.foo
hello: function() { alert('module') };
}
export default api
/* option b) single module declaration
module apiInternalName {
import {foo} from "something"
import {foo as fooOther, bar.foo as fooBar} from "other"
function hello() { alert('module') };
}
*/
single/file.js
module barInternalName {
class foo {}
}
main.js
module api from 'package/file'
module bar from 'single/file'
```
Some thoughts:
- Literal modules are allowed only within packages (no module nesting) or a single module per file
- import() semantics don't change too much (I think)
- The subtle difference is an internal module is the declaration mechanism for exporting an api, a package is used for code organisation.
- The module pattern is optional, can import from packages directly :
```
index.html
<script src="package/file.js"></script>
<script>
// import from package
import {foo, bar} from "other";
</script>
```
What's the history of the unused keyword "package", is it from Java? Been thinking about this lately, could an external module be called a package? package/file.js package "something" { export class foo {} } package "other" { export class foo {} export module bar { export class foo {} } } import {foo as a} from "something" import {foo as b, bar.foo} from "other" /* option a) */ var api = { foo: a, fooOther: b, fooBar: bar.foo hello: function() { alert('module') }; } export default api /* option b) single module declaration module apiInternalName { import {foo} from "something" import {foo as fooOther, bar.foo as fooBar} from "other" function hello() { alert('module') }; } */ single/file.js module barInternalName { class foo {} } main.js module api from 'package/file' module bar from 'single/file' Some thoughts: - Literal modules are allowed only within packages (no module nesting) or a single module per file - import() semantics don't change too much (I think) - The subtle difference is an internal module is the declaration mechanism for exporting an api, a package is used for code organisation. - The module pattern is optional, can import from packages directly : index.html <script src="package/file.js"></script> <script> // import from package import {foo, bar} from "other"; </script> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140411/44105119/attachment.html>