Skip to content

Instantly share code, notes, and snippets.

@knpwrs
Created January 26, 2013 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knpwrs/4644549 to your computer and use it in GitHub Desktop.
Save knpwrs/4644549 to your computer and use it in GitHub Desktop.
These files demonstrate how to make JavaScript / CoffeeScript modules which work in CommonJS, AMD, and vanilla browser environments.
((name, global, definition) ->
if module?
module.exports = definition()
else if define? and typeof define.amd is 'object'
define definition
# alternatively define name definition
else
global[name] = definition()
)('name', @, ->
# return module definition here
)
(function (name, global, definition) {
if (typeof module !== 'undefined') {
module.exports = definition();
} else if (typeof define !== 'undefined' && typeof define.amd === 'object') {
define(definition);
// alternatively define(name, definition);
} else {
global[name] = definition();
}
})('name', this, function () {
// return module definition here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment