ES5 Module Systems (was: Alternative proposal to privateName.public)

Axel Rauschmayer axel at
Mon Dec 26 14:03:28 PST 2011

> Hi Axel, a nice demonstration of the simplicity of the core of AMD is the simplicity with which it can be implemented using a promise library.

Exactly; nice demo. Doing something comparably asynchronous with Node.js modules (without a compilation step) is much more hacky:

>     ({ define: typeof define === "function"
>         ? define
>         : function(A,F) { module.exports = F.apply(null, } }).
>     define([ "./module1", "./module2" ],
>         function (module1, module2) {
>             return ...
>         }
>     );
> [1]
> I like this adapter, and have just changed <> to test that it works with our simple AMD Loader in translation-free SES-on-ES5 (similar to the above, at <>). You can run this test by visiting <> in a modern browser. If you see the line "AMD loader test...succeeded", then it did.
> However, I am confused by the "module.exports = ..." part of your boilerplate. The main CommonJS wiki seems down at the moment, but looking at <> on the mirror site, I could not find any support for this idiom. The closest I could find was <>, which suggests it should read "module.setExports(...);" instead. Where does "module.exports = ..." come from?

It’s necessary for Node.js.


    var module1 = require("./module1");;
    var module2 = require("./module2"); = function() {


    define([ "./module1", "./module2" ],
        function (module1, module2) {
            return { // export
                bar: function () {

Hence, unless you add to `exports`, Node.js won’t see your module’s contributions.

IIRC, Node.js deviates from CJS in that module.exports is an alias for exports. Without that alias, the boilerplate would be more complicated (you’d have to copy the properties of the object produced by F() over to exports). But I am focusing on Node.js, at the moment, so I can afford to rely on this functionality.

Dr. Axel Rauschmayer
axel at


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list