C++博客 联系 聚合 管理  

Blog Stats

随笔档案

好友圈

脚踏实地

心 勿噪

<script type="text/javascript">
 
        void function(global)
        {
            var mapping = {}, cache = {};
            global.define = function(id, func){
                mapping[id] = func;
            };
            
            global.require = function(id){
                if(cache[id])
                    return cache[id];
                else
                    return cache[id] = mapping[id]({});
            };
        }(this);
        
        define("moduleA", function(exports)
        {
            function ClassA(){
            }
            
            ClassA.prototype.print = function(){
                alert("moduleA.ClassA")
            }
            
            exports.New = function(){
                return new ClassA();
            }
        
            return exports;
            
        });
        
        define("moduleB", function(exports)
        {
            function ClassB(){
            }
        
            ClassB.prototype.print = function(){
                alert("moduleB.ClassB")
            }
            
            exports.New = function(){
                return new ClassB();
            }
            
            return exports;
        });
        
        define("moduleC", function(exports)
        {
            function ClassC(){
            }
        
            ClassC.prototype.print = function(){
                var classA = require("moduleA").New();
                classA.print();
                    
                var classB = require("moduleB").New();
                classB.print();
                    
                alert("moduleC.ClassC")
            }
            
            exports.New = function(){
                return new ClassC();
            }
            
            return exports;
        });
        
        var classC = require("moduleC").New();
        classC.print();
        
      </script>
posted on 2016-10-02 20:33 LSH 阅读(25) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
【推荐】超50万行VC++源码: 大型组态工控、电力仿真CAD与GIS源码库
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理