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
On Feb 6, 2008 10:02 PM, Lars Hansen <[EMAIL PROTECTED]> wrote:
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] 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.
>
> --lars
>
> _______________________________________________
> Es4-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es4-discuss
>
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss