Is there a way to have a public function from the module-pattern accessing private variables dynamically? test1 shows what I mean with "access dynamically" but with public variables
var x = (function(){
var x=0, y=2, z=5;
return {
toast: 123,
test1: function(arg){
return this[arg];
},
test2: function(){
// ??
}
};
}());
console.log(x.test1("toast")); // 123
console.log(x.test2("y")); // should return 2
I ended up with creating a single private variable (an object) storing my private variables so I was able to access them like that
privateVarStore[privateVarName]
But is there another solution for that?