Skip to content

Instantly share code, notes, and snippets.

@ricogallo
Last active December 16, 2015 03:49
Show Gist options
  • Save ricogallo/5372755 to your computer and use it in GitHub Desktop.
Save ricogallo/5372755 to your computer and use it in GitHub Desktop.
Universally loadable module
// Universally loadable script, drawn from https://github.com/kriskowal/q
(function (definition) {
// Montage Require
if (typeof bootstrap === "function") {
bootstrap("promise", definition);
// CommonJS
} else if (typeof exports === "object") {
module.exports = definition();
// RequireJS
} else if (typeof define === "function" && define.amd) {
define(definition);
// SES (Secure EcmaScript)
} else if (typeof ses !== "undefined") {
if (!ses.ok()) {
return;
} else {
ses.makeFoo = definition;
}
// <script>
} else {
Foo = definition();
}
})(function () {
"use strict";
return {foo: "bar"}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment