Created
May 27, 2013 23:57
-
-
Save hallettj/5659633 to your computer and use it in GitHub Desktop.
Defining a module in a way that will work in several different environments. This is from Acorn <https://github.com/marijnh/acorn.git>, a JavaScript parser.
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(mod) { | |
if (typeof exports == "object" && typeof module == "object") return mod(exports); // CommonJS | |
if (typeof define == "function" && define.amd) return define(["exports"], mod); // AMD | |
mod(self.acorn || (self.acorn = {})); // Plain browser env | |
})(function(exports) { | |
"use strict"; | |
exports.version = "0.2.0"; | |
/* ... */ | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The AMD line could be written a little differently to avoid relying on the "exports" dependency: