Skip to content

Instantly share code, notes, and snippets.

@cajones
Created January 23, 2012 15:00
Show Gist options
  • Save cajones/1663536 to your computer and use it in GitHub Desktop.
Save cajones/1663536 to your computer and use it in GitHub Desktop.
Possible module boilerplate for AMD, CommonJS and namespace methods
var library =
function(container) {
var stringify = function(obj, rootName) {
/* implementation goes here */
};
container.stringify = stringify;
return container;
}; // define the library in a function, injecting external dependencies if needed
var useAMD = typeof define === "function",
root = this;
if (typeof exports === 'undefined') {
root.JSONX = root.JSONX || {};
}
if (useAMD) {
define('./jsonx', function() {
return library(root.JSONX || exports);
});
} else {
library(root.JSONX || exports);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment