Is it possible to define generic getters / setters for ALL Javascript Objects?
Pseudocode of what I want to do is below. Basically, person and animal route getters and setters to CustomGetter and CustomSetter.
function NewPerson()
{
var person;
var animal;
var person.name = 'John Doe';
console.log("Name: " + person.name); //Prints "Name: JOHNDOE CUSTOM"
var animal.type = 'Herbivore';
console.log("Animal: " + animal.type); //Prints "Animal: HERBIVORE CUSTOM"
console.log("Age: " + person.age); //Prints "Age: NON EXISTANT PROPERTY";
}
function CustomGetter(theObj, propertyName)
{
if(theObj.hasproperty(propertyName))
return ToUpperCase(theObj.propertyName);
else
{
return "NON EXISTANT PROPERTY";
}
}
function CustomSetter(theObj, propertyName, value)
{
if(theObj.hasproperty(propertyName))
theObj.propertyName = value + " CUSTOM";
else
{
console.log("NON PROPERTY TO SET");
}
}
Thank you!