Can you tell me how to get modified private variable as public?
let Module = (function(){
let privateObject = {};
function init(){
privateObject = {test:true}
}
return {
init,
privateObject
}
})();
Module.init();
console.log(Module.privateObject);
I've tried something like this but I am pretty sure that I'm missing something.
let Module = (function(){
function init(){
publicObject.privateObject.test = true;
}
let publicObject = {
privateObject: {},
init
}
return publicObject;
})();
Module.init();
console.log(Module.privateObject); // gives {test: true}
Thank you for your comments.
I already understand why with a new assignment of value
privateObject = {test:true}Module.privateObject returned an empty object because Module.privateObject kept a reference to the previous value of privateObject. Thanks @jabaa
As a solution to the problem for the posterity, the following code works like a charm