Skip to content

Instantly share code, notes, and snippets.

@bgaze
Created March 17, 2019 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgaze/119ac958d16523c02c5711bc60258ea6 to your computer and use it in GitHub Desktop.
Save bgaze/119ac958d16523c02c5711bc60258ea6 to your computer and use it in GitHub Desktop.
Javascript Universal Module Definition pattern
(function (root, factory) {
if (typeof define === "function" && define.amd) {
define(["jquery"], function (jQuery) {
return (root.myfn = factory(jQuery));
});
} else if (typeof module === "object" && module.exports) {
module.exports = (root.myfn = factory(require("jquery")));
} else {
root.myfn = factory(root.jQuery);
}
}(this, function ($) {
function myfn() {
// ...
}
return myfn;
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment