JSFiddle - React, Tailwind, and code Playground

by ChaseWest

JavaScript

var ModuleA = function() {
    //set two public variables (as ana example)
    this.name = "A";
    this.description = "this is module A";
}

ModuleA.prototype = function() {
    //private stuff/functions
    function doSomething() {
        return "I DID SOMETHING";
    }

    //public api
    return {
        doSomething : doSomething
    };
}();


var ModuleB = function(moduleA) {
    this.moduleA = moduleA;
}

ModuleB.prototype = function() {
    //private stuff/functions
    function someMethod() {
        console.log(moduleA.doSomething());
    }

    //public api
    return {
        someMethod : someMethod
    };
}();

//create a new object: moduleA
var moduleA = new ModuleA();

//using the moduleB
var module = new ModuleB(moduleA);
module.someMethod();