Java Reference
In-Depth Information
Now it's impossible to change the values of _color , but they can be accessed using the
getter methods:
raph.getColor();
<< "Red"
You could also add a setter method to allow private properties to be changed in a controlled
way. This means that you can stop certain assignments from being made by screening the
data before any changes are made to a property:
this.setColor = function(color) {
if(typeof color === "string"){
return _color = color;
} else {
throw new Error("Color must be a string");
}
}
raph.setColor("Pink");
<< "Pink";
raph.getColor();
<< "Pink"
Search WWH ::




Custom Search