Created
November 26, 2011 14:55
-
-
Save unscriptable/1395806 to your computer and use it in GitHub Desktop.
AMD/Node module with dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)); | |
} | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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