Extracting getters and setters

Lars Hansen lhansen at adobe.com
Wed Feb 6 14:02:00 PST 2008


> -----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.

--lars



More information about the Es4-discuss mailing list