Skip to content

Instantly share code, notes, and snippets.

@pid
Created July 29, 2013 10:15
Show Gist options
  • Select an option

  • Save pid/6103387 to your computer and use it in GitHub Desktop.

Select an option

Save pid/6103387 to your computer and use it in GitHub Desktop.
Adding AMD into the mix and don't forget CommonJS
/* Thanks to http://oli.me.uk/2013/07/21/exporting-through-amd-commonjs-and-the-global-object/ */
(function () {
// YOUR ORIGINAL CODE HERE
if (typeof define === 'function' && define.amd) {
define(function () {
return Foo;
});
}
else if (typeof module !== 'undefined' && module.exports) {
module.exports = Foo;
// Or maybe: module.exports.Foo = Foo;
// It's up to you really.
}
else {
this.Foo = Foo;
}
}.call(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment