Getters and Setters in JavaScript
This is the fourth article in the series of Object Oriented Javascript . Following our discussion on inheritance and it's integration with modular design pattern , I'd like take a deeper look into encapsulation and usage of mutator methods . Getters and setters allow you to build useful shortcuts for accessing and mutating data within an object. __defineGetter__ and __defineSetter__ If you had searched for the information over the internet, you would have probably encountered recommendations, mostly from Microsoft :), to use __defineGetter__ and __defineSetter__ . You may have also found some hacks for IE7 and even IE6. Even from a look at them you can smell something fishy. JavaScript is not C and doesn't encourage usage of underscores. Your gut feeling is right. This feature has been removed from the Web standards. Though some browsers may still support it, it is in the process of being dropped. Do not use it in old or new projects. Pages o...