Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@derek
Created October 20, 2011 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derek/02ebc7869df707fd3ab2 to your computer and use it in GitHub Desktop.
Save derek/02ebc7869df707fd3ab2 to your computer and use it in GitHub Desktop.

The Specs

CommonJS Modules/1.1 http://wiki.commonjs.org/wiki/Modules/1.1

CommonJS Modules/2.0 (draft) http://www.page.ca/~wes/CommonJS/modules-2.0-draft8/

AMD Modules https://github.com/amdjs/amdjs-api/wiki/AMD

Harmony Modules (note: Not backwards-compatible with ES3) http://wiki.ecmascript.org/doku.php?id=harmony:modules

Examples

// YUI
YUI.add([identifier], function(Y){
            
    // Export Y.foobar
    Y.foobar = "YUI!";
    
    // Export Y.baz as a concatenation of two imported values
    Y.baz = Y.fizz + Y.buzz;
    
}, [version,] [config/dependencies] );


// AMD
define([name,] ["dependencyA", "dependencyB"], function(dependencyA, dependencyB){

    // Always returns an object
    return {…};

});


// CommonJS Modules/1.1 + Wrapper
define(function(require, exports, module) {
    //Require is passed in as a local
    var someModule = require("someModule");

    // Exports is what you hang values/functions off of, similar to Y.
    exports.baz = someModule.bop;
    exports.fizzbuzz = function() {
        ...
    }
});


// CommonJS Modules/2.0
module.declare([identifier,] function(require, exports, module) {
    exports.hello = function() {
        return "Hello World"; 
    }
});

Informative AMD Presentations

YUI Plugin for RequireJS

There are a few issues, but seems to work reasonably well and is a nice proof of concept. I'll ask if he is actually using this in a live application. https://github.com/WilcoFiers/UseYUI-for-RequireJS

Mailing Lists

Interesting Discussions/Perspectives

AMD supported in Node.js (then later removed) http://groups.google.com/group/nodejs-dev/browse_thread/thread/c084c613c4cb9363

AMD no longer a CommonJS spec http://groups.google.com/group/commonjs/browse_thread/thread/96a0963bcb4ca78f/cf73db49ce267ce1?lnk=gst#

Mikeal's thoughts on Node.js & AMD http://groups.google.com/group/commonjs/browse_thread/thread/b22da8744d9fd603/04b9fa446905474b

Perspectives on YUI's modules (hint: ctrl-f "YUI") http://requirejs.org/docs/history.html http://tagneto.blogspot.com/2011/04/on-inventing-js-module-formats-and.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment