zoukankan      html  css  js  c++  java
  • 通用模块设计UMD

    https://leohxj.gitbooks.io/front-end-database/content/javascript-modules/about-umd.html

    UMD(universal module definition),希望提供一个前后端跨平台的解决方案(支持AMD与CommonJS模块方式)。

    实现原理

    UMD的实现很简单:

      1.先判断是否支持Node.js模块格式(exports是否存在),存在则使用Node.js模块格式。

      2.再判断是否支持AMD(define是否存在),存在则使用AMD方式加载模块。

      3.前两个都不存在,则将模块公开到全局(window或global)。

    jQuery使用示例:  

            //if the module has no dependencies, the above pattern can be simplified to
            (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 taht support module.exports, like Node
                    module.exports=factory();
                }else{
                    //Browser globals (root is window)
                    root.returnExports=factory();
                }
            }(this,function(){
                //Just return a value to define the module export.
                //This example returns an object, but the module can return a function as the exported value.
                return {};
            }))

    认识AMD、CMD、UMD、CommonJS

    https://www.cnblogs.com/humin/p/5389901.html

  • 相关阅读:
    hdu4738(双连通分量)
    hdu4635(强连通缩点)
    hdu4612(双连通缩点+树的直径)
    poj3177(边双连通分量+缩点)
    poj3694(tarjan缩点+lca)
    hdu5171(矩阵快速幂)
    uva796(求桥数目)
    uva315(求割点数目)
    POJ1058 The Gourmet Club
    POJ1057 FILE MAPPING
  • 原文地址:https://www.cnblogs.com/em2464/p/10368294.html
Copyright © 2011-2022 走看看