美文网首页
模块管理

模块管理

作者: 村长很忙 | 来源:发表于2017-05-24 11:23 被阅读3次
var ModulesManage = (function() {

        var modules = {};

        function defined(name, deps, impl) {
            for (var i = 0; i < deps.length; i++) {
                deps[i] = modules[deps[i]];
            }

            modules[name] = impl.apply(impl, deps);
        };

        function get(name) {
            return modules[name];
        };

        return {
            define: defined,
            get: get
        };

    }());


    ModulesManage.define("Person", [], function() {

        function ctor(name, age, gender) {
            this.name = name;
            this.age = age;
            this.gender = gender;
        }

        function eatfood(food) {
            console.log(this.name + "eat" + food);
        }

        ctor.prototype = {
            EatFood: eatfood
        };

        return ctor;
    });




    var wsp = new(ModulesManage.get("Person"))("Wsp", 20, "Male");

    wsp.EatFood("香蕉");

相关文章

网友评论

      本文标题:模块管理

      本文链接:https://www.haomeiwen.com/subject/ucgnxxtx.html