我看到JS库使用这两种不同的实现。 CommonJS线只有不同之处。UMD:是否正在分配给module.exports冗余?
它们在功能上是否相同?将值分配给module.exports不是必需的吗?
/* 1: Assignment to module.exports */
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS
module.exports = factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
$.fn.jqueryPlugin = function() { return true; };
}));
/* 2: Doesn't assign to module.exports */
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery'], factory);
} else if (typeof module === 'object' && module.exports) {
// CommonJS
factory(require('jquery'));
} else {
// Browser globals
factory(jQuery);
}
}(function($) {
$.fn.jqueryPlugin = function() { return true; };
}));