I have a function which has some variable since they are inside a function, they are local to function hence private. Now I may have many such variable, inorder to set a value and get the variable value from outside, I have to write set and get for every private variable. Is there anyway in javascript to have common function for getting and setting all private variable(PrivateOne and PrivateTwo).
privateClosure = (function(){
var PrivateOne;
var PrivateTwo;
setPrivate = function(VariableName,Value)
{
VariableName = Value;
}
getPrivate = function(VariableName)
{
return VariableName;
}
return{setPrivate,getPrivate};
})();
// I want to do something like this
privateClosure.setPrivate(PrivateOne,10);
privateClosure.getPrivate(PrivateOne);
privateClosure.setPrivate(PrivateTwo,20);
privateClosure.getPrivate(PrivateTwo);
//Only one Function for all the private variable in closure.
Is there anyway in javascript to have common function for getting and setting all private variable(PrivateOne and PrivateTwo).