ES6 modules (sorry...)

C. Scott Ananian ecmascript at
Mon Jun 16 12:24:49 PDT 2014

Another alternative is to introduce this funny "binding not
destructing" behavior as a first-class language construct, so that one
could do:

let o = { f: 1 };
let < f > = o;  // using your angle-bracket syntax for the sake of discussion
o.f = 2;
console.log(f); // prints '2'

let < foo > = import "module"; // same syntax!

Of course this is far too large a change for this late date, etc, etc.
But my point is that "modules as objects" works well because it fits
well with the rest of the language.  If we want `f` to be an
abbreviation for `o.f` then it would be nice if that binding behavior
was part of the base language.

ps. my personal preference is *not* to introduce new 'binding' syntax,
but instead to imagine the values assigned as a result of the
destructuring as being somewhat magical proxies which retain their tie
to the original module object and reflect changes there.  Using
proxies as a mental model of the semantics avoids having to muck
around with the core notion of variable binding.  That is, it really
is a `let`, and it really is ordinary `destructuring` -- all the magic
resides in the particular value returned.

More information about the es-discuss mailing list