Skip to content

Instantly share code, notes, and snippets.

@bpander
Created August 31, 2013 05:35
Show Gist options
  • Save bpander/6396399 to your computer and use it in GitHub Desktop.
Save bpander/6396399 to your computer and use it in GitHub Desktop.
How to define a js module
(function (definition) {
// Turn off strict mode for this function so we can assign to global
/* jshint strict: false */
// 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.makeQ = definition;
}
// <script>
} else {
Module = definition();
}
})(function () {
"use strict";
// THE ACTUAL MODULE DEFINITION
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment