Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Forked from kriskowal/commonjs-adapter.js
Created January 25, 2010 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tmpvar/286314 to your computer and use it in GitHub Desktop.
Save tmpvar/286314 to your computer and use it in GitHub Desktop.
(function (exports) {
// because the anonymous function is being called without a scope being set,
// "this" will refer to the global scope. In a browser, that's the window, but
// will be "undefined" in strict mode. In other JS platforms, it may be some
// other thing.
// my code here.
// don't make accidental globals.
// hang a small number of things on the "exports" object.
exports.MyThing = "squarrrrrkkk!!!";
})(
// exports will be set in any commonjs platform; use it if it's available
typeof exports !== "undefined" ?
exports :
// otherwise construct a name space. outside the anonymous function,
// "this" will always be "window" in a browser, even in strict mode.
this.NAMESPACE = {}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment