Extracting getters and setters
-----Original Message----- From: es4-discuss-bounces at mozilla.org [mailto:es4-discuss-bounces at mozilla.org] On Behalf Of Michael O'Brien Sent: 6. februar 2008 13:06 To: es4-discuss Discuss Subject: Extracting getters and setters
Question about getters and setters. Can you assign a getter / setter to a var and invoke later? i.e. can you extract a getter/setter method?
Consider:
class Shape { function get width(): int { return 1; }
function set width(value: int): void { } /* Does this assign the getter or setter */ var fun = width
}
var s: Shape = new Shape s.fun()
ASC will extract the getter.
That's surprising to me.
But what should ES4 do? How can you extract the getter or the setter or both?
I would like to argue you should not be able to. Firefox has facilities, methods called getter and setter IIRC, that extracts them. And I think that if ES4 allows them to be extracted that's the only way to go.
Under the hood, is the width getter/setter to be stored as one property or 2 and what is the property name?
It doesn't feel natural for the language spec to talk about that, esp if it's not observable.
ES4 needs to treat getter/setters identically to normal vars. Otherwise it kind of defeats the point of having them.
I would expect:
var fun = width;
to invoke the getter. In that particular case, I'd expect a compile error because width can't be accessed from static scope, exactly as if it was declared as a var.
If implementations want to also expose get properties to access the functions, then that is up to them, but I think it's quite important that ES4 treats getter/setters exactly like variables.
Peter
An HTML attachment was scrubbed... URL: esdiscuss/attachments/20080206/bca7668a/attachment-0002
Question about getters and setters. Can you assign a getter / setter to a var and invoke later? i.e. can you extract a getter/setter method?
Consider:
class Shape { function get width(): int { return 1; }
}
var s: Shape = new Shape s.fun()
ASC will extract the getter. But what should ES4 do? How can you extract the getter or the setter or both?
Under the hood, is the width getter/setter to be stored as one property or 2 and what is the property name?
Thanks
Michael O'Brien