Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active February 11, 2024 22:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cowboy/5779604 to your computer and use it in GitHub Desktop.
Save cowboy/5779604 to your computer and use it in GitHub Desktop.
The "UMD returnExportsGlobal shuffle"
// Re. https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js
// ==================================================
// Q. Does all that UMD stuff need to be at the top?
// ==================================================
(function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], function (b) {
return (root.returnExportsGlobal = factory(b));
});
} else {
// Browser globals
root.returnExportsGlobal = factory(root.b);
}
}(this, function (b) {
//use b in some fashion.
// Just return a value to define the module export.
// This example returns an object, but the module
// can return a function as the exported value.
return {};
}));
// ==================================================
// A. Not really.
// ==================================================
(function (factory, umd, root) {
umd(root, factory);
}(function (b) {
//use b in some fashion.
// Just return a value to define the module export.
// This example returns an object, but the module
// can return a function as the exported value.
return {};
}, function (root, factory) {
if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// like Node.
module.exports = factory(require('b'));
} else if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['b'], function (b) {
return (root.returnExportsGlobal = factory(b));
});
} else {
// Browser globals
root.returnExportsGlobal = factory(root.b);
}
}, this));
@ryanramage
Copy link

I see what you did there....nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment