Skip to content

Instantly share code, notes, and snippets.

@rauschma
Created January 23, 2012 15:36
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rauschma/1663811 to your computer and use it in GitHub Desktop.
Save rauschma/1663811 to your computer and use it in GitHub Desktop.
Triple module boilerplate: Node.js, AMD, plain browser
// 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 () { }
};
});
@Raynos
Copy link

Raynos commented Jan 23, 2012

Can this be done as a (global || window).define = ... so we don't have to dump boilerplate everywhere?

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