Javascript实现一个插件

写一个插件,兼容commonjs,amd,cmd,原生js。

;(function (global, factory) {
    if(typeof define == 'function' && define.amd){
      define([], factory);//amd
    }else if(typeof module === 'object' && typeof module.exports == 'object'){
      module.exports = factory();//commonjs
    }else{
      global.myJsPlugin = factory();
    }
})(this, (function () {
    const myJsPlugin = {
        //在这里定义对象的属性和方法
    };
    return myJsPlugin;
}))
原文地址:https://www.cnblogs.com/camille666/p/js_plugins.html