Last active
February 11, 2024 22:42
-
-
Save CrocoDillon/9990078 to your computer and use it in GitHub Desktop.
Export your awesome module using AMD, CommonJS, Node.js or just as global.
This file contains 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
/* | |
* Inspiration from: | |
* https://github.com/jquery/jquery/blob/master/src/intro.js | |
* | |
* Thanks jQuery! | |
* | |
* This is another way to handle dependencies (in this case, a window with a document) | |
*/ | |
(function( global, factory ) { | |
if ( typeof module === "object" && typeof module.exports === "object" ) { | |
// For CommonJS and CommonJS-like environments where a proper window is present, | |
// execute the factory and get jQuery | |
// For environments that do not inherently posses a window with a document | |
// (such as Node.js), expose a jQuery-making factory as module.exports | |
module.exports = global.document ? | |
factory( global, true ) : | |
function( w ) { | |
if ( !w.document ) { | |
throw new Error( "jQuery requires a window with a document" ); | |
} | |
return factory( w ); | |
}; | |
} else { | |
factory( global ); | |
} | |
// Pass this if window is not defined yet | |
}(typeof window !== "undefined" ? window : this, function( window, noGlobal ) { | |
// Awesome module gets created here | |
})); |
This file contains 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
/* | |
* Inspiration from: | |
* https://github.com/addyosmani/memoize.js/blob/master/memoize.js | |
* | |
* Thanks Addy! | |
*/ | |
(function (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define([], factory); | |
} else if (typeof exports === 'object') { | |
// Node. Does not work with strict CommonJS, but | |
// only CommonJS-like environments that support module.exports, | |
// like Node. | |
module.exports = factory(); | |
} else { | |
// Browser globals (root is window) | |
root.memoize = factory(); | |
} | |
}(this, function() { | |
"use strict"; | |
var memoize = function(func) { | |
/* Your awesome module logic here */ | |
}; | |
return memoize; | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey I am going through the jquery 3.2.1, find the first part of this, but coz i am not familiar with module, i cant figure out this part is for. would you mind give me a little explanation? thank you