如何在Javascript中注入模块?

时间:2016-03-30 07:09:36

标签: javascript jquery angularjs design-patterns

我正在使用Module模式,现在我想知道可以将一个模块注入另一个模块,如AngularJs。

下面是我尝试过的示例代码。

module.js

var AnotherModule = (function () {

    function AnotherModule() {
        this.anotherFunction = function () {
            alert('Inside another Module');
        }
    }
    return AnotherModule;

})(window);

var AnotherModule = new AnotherModule();

var Module = (function (window, AnotherModule) {

    function Module(AnotherModule) {

        var privateMethod = function() {

        }

        this.getName = function (brand) {
            console.log('Inside get Name');
            console.log(AnotherModule);
        }

    }
    return Module;

})(window, AnotherModule);


var module = new Module();
module.getName();

0 个答案:

没有答案
相关问题