Skip to content

Instantly share code, notes, and snippets.

@unscriptable
Created November 9, 2011 03:04
Show Gist options
  • Save unscriptable/1350202 to your computer and use it in GitHub Desktop.
Save unscriptable/1350202 to your computer and use it in GitHub Desktop.
boilerplate for CommonJS, AMD, plain old global hackfest
(function (myLib, define) {
//Set up myLib here.
myLib.add = function (a, b) { return a + b; };
define(myLib);
}.call(this,
typeof exports == 'object' ? exports : {},
typeof define == 'function' && define.amd ?
define :
function (lib) { typeof exports == 'object' || this.myLib = lib; }
);
(function (myLib, define) {
//Set up myLib here.
myLib.add = function (a, b) { return a + b; };
define(myLib);
}.call(this,
typeof exports == 'object' ? exports : {},
typeof define == 'function' && define.amd ?
define :
function (lib) { typeof exports == 'object' || (this.myLib = lib); }
));
(function (myLib, define) {
//Set up myLib here.
myLib.add = function (a, b) { return a + b; };
define(myLib);
}.apply(this, typeof exports == 'object' ?
[exports, function () {}] :
[{}, typeof define == 'function' && define.amd ? define : function (lib) { this.myLib = lib; }]
));
// no global hackfest
(function (myLib, define) {
//Set up myLib here.
myLib.add = function (a, b) { return a + b; };
define(myLib);
}.call(this,
typeof exports == 'object' ? exports : {},
typeof define == 'function' && define.amd ? define : function () {}
));
// no global hackfest
var define = typeof define == 'undefined' ? function (def) { def(require, exports, module); } : define;
define(function (require, exports, module) {
//Set up myLib here.
exports.add = function (a, b) { return a + b; };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment