Implicit setters and getters
Hi
This might be more a javascript syntax question, but here goes:
I create a object def like this:
function MyObjectDef()
{
this.initialize();
};
MyObjectDef.prototype.initialize = function()
{
this.a = 10;
}
var mo = new MyObjectDef();
alert(mo.a);
Question is, how do I create an implicit setter for that object? I know I could do this:
MyObjectDef.prototype.setA = function(v)
{
this.a = v*2;
}
mo.setA(10);
alert(mo.a); // would return 20
But I would much prefer something like this (which obviously doesn't work):
MyObjectDef.prototype.set a = function(v)
{
this.a = v*2;
}
mo.a = 10;
alert(mo.a); // would return 20
Any help?
Thanks,
Jakob
