Remarks about module import

Peter Michaux petermichaux at
Sat Aug 23 20:21:01 PDT 2008

On Sat, Aug 23, 2008 at 7:16 PM, Kris Kowal <kris.kowal at> wrote:


> /* these are modules by the same author, in the same directory */
> from "./urllib.js" import urlJoin;

I don't know if some sugary syntax like above will be used (or the
destructuring syntax will win) but if it is then it might be good to
be able to write

from "./urllib.js" import urlJoin as uj;

Or even more SQL-like

import urlJoin as uj from "./urllib.js";

The destructuring syntax presented in this thread would allow for this
type of renaming during import. I like the destructuring syntax more
and it doesn't involve any new keywords.

> /* using let or var makes a variable private to the module */

Are "file" and "module" synonymous?

I don't think a file should be equivalent to a module because it
should be possible to concatenate and minify many modules into a
single file for distribution to build fast websites. I don't think it
is a good idea to entrench the need for many HTTP requests directly
into the JavaScript language.


> /* assigning to "this" makes it an export */
> this.sink = function (element, widget, eventName) {

What do you call the "this" object? In ES3 it would be "the global object".

I don't really like assigning to "this" is the syntax for making
importable symbols. I think something that involves a keyword like
"export" or "provides" is more declarative.


> <index.js>

Next line allows for multiple imports

> from "./sink.js" import sink; // or

Next line allows for only one import

> let sink = require("./sink.js").sink;

or with the destructuring

let {sink: sink} = require("./sink.js");

or with the shorthand destructuring

let {sink} = require("./sink.js");



More information about the Es-discuss mailing list