Module loader interop scenarios

Sam Tobin-Hochstadt samth at
Wed Nov 16 11:34:41 PST 2011

2011/11/11 Luke Hoban <lukeh at>:
> At a high level - there are four interop scenarios that we want to support - (1) modules defined in ES6 syntax and consumed in ES6 syntax, (2) modules defined in ES6 syntax and consumed in ES5 syntax, (3) modules defined in ES5 syntax and consumed in ES6 syntax, and (4) modules defined in ES5 syntax and consumed in ES5 syntax.

We want to support all of these scenarios, basically as you describe.

[snip 1 & 2]

> (3) I can't quite piece together whether the current proposal supports this - but if it does, it is somewhat indirect.  This would seem to be an important interop scenario, to allow libraries to continue offering a single codebase defined in ES5 syntax that can be consumed using a polyfill from either ES6 or ES5 syntax.  Does the below example behave as I'm expecting?  Any reason why the module loaders API doesn't include a 'defineModule' function that provides the equivalent of AMD 'define', so that existing AMD code (or any other interoperable JavaScript module pattern) can be consumed as ES6 modules from ES6 syntax?

The code below should work, exactly as written.  Are you asking for a
loader.defineModule() function, which would work like this:

function defineModule(name, exports, mods) {
  this.loaded[name] = this.createModule(exports, mods);

Certainly we could add a convenience function like this, although I'm
not sure if this is exactly the right API.

>        <script type="text/javascript">
>        function sum(x, y) {
>            return x + y;
>        }
>        var pi = 3.141593;
>        Object.System.loaded.math = Object.System.createModule({
>            sum: sum,
>            pi: pi
>        }, {});
>        </script>
>        <script type="harmony">
>        import {sum, pi} from math;
>        alert("2π = " + sum(pi, pi));
>        </script>
sam th
samth at

More information about the es-discuss mailing list