JSFiddle - React, Tailwind, and code Playground

JavaScript

getterTest = function() {
    var _x = 15;
    
    return {
        doSomething: function() {
           _x += 5;
        },
    
        get x() {
            return _x;
        }
    }
    }();
    
    //code in file1.js
    //console.log(getterTest._x);         //this is private so can't be access
    console.log(getterTest.x);         //should give 15
    getterTest.doSomething();
    console.log(getterTest.x);        //should give 20