Skip to content

Instantly share code, notes, and snippets.

@rauschma
Created November 15, 2012 18:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rauschma/4080200 to your computer and use it in GitHub Desktop.
Save rauschma/4080200 to your computer and use it in GitHub Desktop.
Modules: AMD versus CJS
//---------------------
// AMD
define(["foo", "bar", "baz"], function (foo, bar, baz) {
return {
func: function (...) { ... }
};
});
//---------------------
// CJS/Node.js
var foo = require("foo");
var bar = require("bar");
var baz = require("baz");
exports.func = function (...) { ... };
@Raynos
Copy link

Raynos commented Nov 15, 2012

exports.func is evil. Use module.exports = function () {}

@johnjbarton
Copy link

I don't think the syntax differences are important. What is important: browsers require async and async is harder to use. Syntax is a side effect: browsers require async and async in JS requires callbacks. Hence AMD.

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