Created
January 26, 2013 20:54
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((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 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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