function run(argument) {
let Public = {}
let Private = myClass().setFoo(argument)
Public.getFoo = Private.getFoo
return Public;
}
function myClass() {
let Public = {};
let Private = {};
Private.foo = null;
Public.setFoo = function (arg) { Private.foo = arg; return Public};
Public.getFoo = function () { return Private.foo };
return Public;
}
Public.getFoo = Private.getFoo
;Public.getFoo = Private._getFoo
It seams like Apps Script IDE understand both of them are the same object, so it would call itself infinetely. But why does that happen if I'm not referring to the same object?
Years later, after reviewing this project, I've come to some conclusions:
function runMe() {
const obj = createObject();
obj.setValue('foo'); //logged value:'foo'
console.log(obj.privateValue); //throws error (not acessible)
};
function createObject() {
let privateValue = null;
return { setValue:(arg)=>{/* sets value and logs it */} }
};
runMe();
The article suggested by @David Salomon, in the previous answer, written by Basti Ortiz, was insanely helpful at that time. Thanks, David!