js插件开发兼容commonJS、AMD、CDM的UMD写法

(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
    typeof define === 'function' && define.amd ? define(factory) :
    (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.testPlugin = factory());
}(this, (function () {
    // do somethings
    var testPlugin = function(option){
        console.log('option=====',option);
    }
    return testPlugin
})));

 

参考html2canvas插件源码

参考:https://www.cnblogs.com/niklai/p/6095974.html

posted @ 2021-10-14 11:12  凌晨肆点的洛杉矶  阅读(169)  评论(0编辑  收藏  举报