zoukankan      html  css  js  c++  java
  • 现代的模块机制

    大多数模块依赖加载器/ 管理器本质上都是将这种模块定义封装进一个友好的API

    <!DOCTYPE html>
    <html lang="en" dir="ltr">
      <head>
        <meta charset="utf-8">
        <title></title>
      </head>
      <script type="text/javascript">
          var MyModules=(function Manager(){
            var modules={};
            function define(name,deps,impl){
              for(var i=0;i<deps.length;i++){
                deps[i]=modules[deps[i]];
              }
              console.log(deps);
              modules[name]=impl.apply(impl,deps)
            }
            function get(name) {
              return modules[name];
            }
            return {
              define:define,
              get:get
            }
          })()
    
      MyModules.define("bar",[],function (words) {
    
        function hello(who){
          console.log(words);
          return "Let me introduce:"+who;
        }
        return {
          hello:hello
        }
      })
    
      MyModules.define("foo",["bar"],function(words){
        var hungry="hippo";
        function awesome(){
          console.log(words);
          console.log(bar.hello(hungry).toUpperCase());
        }
        return {
          awesome:awesome
        }
      })
    
        var bar=MyModules.get("bar");
        var foo=MyModules.get("foo");
    
        console.log(bar.hello("hippo"));
        foo.awesome();
      </script>
      <body>
    
      </body>
    </html>
  • 相关阅读:
    hdu 2680(最短路)
    hdu 1548(最短路)
    hdu 1596(最短路变形)
    hdu 1546(dijkstra)
    hdu 3790(SPFA)
    hdu 2544(SPFA)
    CodeForces 597B Restaurant
    CodeForces 597A Divisibility
    CodeForces 598E Chocolate Bar
    CodeForces 598D Igor In the Museum
  • 原文地址:https://www.cnblogs.com/saonian/p/9707882.html
Copyright © 2011-2022 走看看