Created
January 23, 2012 15:36
-
-
Save rauschma/1663811 to your computer and use it in GitHub Desktop.
Triple module boilerplate: Node.js, AMD, plain browser
This file contains hidden or 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
// No imports, those are more work, especially for plain browser. | |
// However, as soon as you have imports, you should switch to AMD on browsers. | |
// Related: http://www.2ality.com/2011/11/module-gap.html | |
({ define: | |
typeof define === "function" ? | |
define | |
: typeof module !== "undefined" ? | |
function(F) { module.exports = F() } | |
: function(F) { this.defClass = F() }.bind(this) | |
}). | |
define(function () { | |
return { | |
foo: function () { } | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can this be done as a
(global || window).define = ...
so we don't have to dump boilerplate everywhere?