2014-06-21 02:54:08 +00:00
|
|
|
---
|
|
|
|
title: Universal JS module loader
|
2018-12-06 22:15:40 +00:00
|
|
|
category: JavaScript libraries
|
2014-06-21 02:54:08 +00:00
|
|
|
---
|
|
|
|
|
2023-03-13 12:02:33 +00:00
|
|
|
### Reference
|
|
|
|
|
|
|
|
* <https://github.com/umdjs/umd>
|
|
|
|
|
2014-06-21 02:58:36 +00:00
|
|
|
### [With dependency](https://github.com/umdjs/umd/blob/master/amdWebGlobal.js)
|
2014-06-21 02:54:08 +00:00
|
|
|
|
|
|
|
~~~ js
|
|
|
|
;(function (root, factory) {
|
|
|
|
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define(['jquery'], factory);
|
|
|
|
} else if (typeof exports === 'object') {
|
|
|
|
module.exports = factory(require('jquery'));
|
|
|
|
} else {
|
|
|
|
root.YourModule = factory(root.jQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
}(this, function (jquery) {
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
~~~
|
|
|
|
|
2014-06-21 02:58:36 +00:00
|
|
|
### No dependencies
|
2014-06-21 02:54:08 +00:00
|
|
|
|
|
|
|
~~~ js
|
|
|
|
;(function (root, factory) {
|
|
|
|
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define(factory);
|
|
|
|
} else if (typeof exports === 'object') {
|
|
|
|
module.exports = factory();
|
|
|
|
} else {
|
|
|
|
root.YourModule = factory();
|
|
|
|
}
|
|
|
|
|
|
|
|
}(this, function () {
|
|
|
|
return {};
|
|
|
|
}));
|
|
|
|
~~~
|
|
|
|
|
2014-06-21 02:58:36 +00:00
|
|
|
### [Supports circular references](https://github.com/umdjs/umd/blob/master/commonjsStrict.js)
|
|
|
|
|
|
|
|
~~~ js
|
|
|
|
(function (root, factory) {
|
|
|
|
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define(['exports', 'jquery'], factory);
|
|
|
|
} else if (typeof exports === 'object') {
|
|
|
|
factory(exports, require('jquery'));
|
|
|
|
} else {
|
|
|
|
factory((root.YourModule = {}), root.jQuery);
|
|
|
|
}
|
|
|
|
|
|
|
|
}(this, function (exports, jQuery) {
|
|
|
|
exports.action = function () {};
|
|
|
|
}));
|
|
|
|
~~~
|