From: Oltmans on 15 Jul 2010 13:41 Hi JavaScript gurus, just a newbie to JavaScript and came across the module pattern. I'm not really sure about how to go about implementing getter/setter in the module pattern. BTW, I'm not even sure if implementing the getter setter within the module pattern is a good idea. Here is a short example var g = function(){ var value = 0; var value1= 0; var value2= 0; return { setter:function(k,v){ //this is the setter function } }; }(); So what I'm trying to do here is that when I call g.setter('value',10) it should set variable 'value' to 10. Likewise, g.setter('value2',50) should set the 'value2' to 50. I'm not sure if this is the right approach. So should I be implementing getter/setters in a module pattern like this or there is a better way of doing it? Please pardon my ignorance and enlighten me. Thanks for all the help in advance. Best regards, Oltmans
|
Pages: 1 Prev: Bug in Safari 5 Next: Object oriented javascript question |