mercredi 30 mars 2016

How can I inject Modules in Javascript?

I'm using Module pattern, now I wanted to know is that possible to inject one module into another like AngularJs.

Below is sample code that I've tried.

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();

Aucun commentaire:

Enregistrer un commentaire