Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created November 26, 2011 14:55
Show Gist options
  • Save unscriptable/1395806 to your computer and use it in GitHub Desktop.
Save unscriptable/1395806 to your computer and use it in GitHub Desktop.
AMD/Node module with dependencies
(function (define) {
define(['pkgA/modA', 'pkgB/mod2'], function (modA, mod2) {
// define and return module here
function myCtor () {}
myCtor.prototype = {
combine: function () { return modA.aMethod() + mod2.anotherMethod();
};
return myCtor;
});
}(typeof define == 'function' && define.amd ?
define :
function (deps, factory) {
module.exports = factory.apply(this, deps.map(require));
}
));
// if we're not concerned about some other free variable called "define"
// then won't this work?
var define;define||(define=function(deps,fact){module.exports=fact.apply(this,deps.map(require))});
define(['pkgA/modA', 'pkgB/mod2'], function (modA, mod2) {
// define and return module here
function myCtor () {}
myCtor.prototype = {
combine: function () { return modA.aMethod() + mod2.anotherMethod();
};
return myCtor;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment