JSFiddle - React, Tailwind, and code Playground

JavaScript

var TheObject = function () {
    var instance;

    function init() {
        var that = this;
        var foo = 1;

        function consoleIt() {
            console.log(that, foo);
        }
        return {
            bar: function () {
                consoleIt()
            }
        };
    }
    return {
        getInstance: function () {
            if (!instance) {
                instance = init();
            }
            return instance;
        }
    };
}();
var myObject = TheObject.getInstance();
myObject.bar();