Skip to content

Instantly share code, notes, and snippets.

@mikaelbr
Created October 5, 2012 15:37
Show Gist options
  • Save mikaelbr/3840565 to your computer and use it in GitHub Desktop.
Save mikaelbr/3840565 to your computer and use it in GitHub Desktop.
JS Module Template
;(function () {
var moduleName = 'someName',
methods = {},
root = this;
// Private methods
var _foo = function () {
};
// Public methods
methods.foo = function () {
};
// - From async.js
// AMD / RequireJS
if (typeof define !== 'undefined' && define.amd) {
define(moduleName, [], function () {
return methods;
});
}
// Node.js
else if (typeof module !== 'undefined' && module.exports) {
module.exports = methods;
}
// included directly via <script> tag
else {
root[moduleName] = methods;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment