Questions about setters

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Questions about setters

P T Withington
Can I override a setter?  Can I call the setter I override using  
super?  How exactly?

> class foo {
>   var barstate;
>   function set bar (value) { barstate = bar }
>   function get bar () { return barstate }
> }
>
> class annotatedFoo {
>   override function set bar (value) {
>     note('setting bar');
>     // how do I call my super?
>     super['set bar'](value);
>   }
>   override function get bar () {
>     note('getting bar');
>     // how do I call my super?
>     return super['get bar']();
>   }
> }

Can `super` by itself mean "call next method"?  That would seem like a  
useful shortcut, and avoid the question of how you call a method with  
a space in its name.
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

RE: Questions about setters

Lars Hansen-3
> -----Original Message-----
> From: [hidden email] [mailto:es4-discuss-
> [hidden email]] On Behalf Of P T Withington
> Sent: 24. juli 2008 22:30
> To: [hidden email] es4-discuss
> Subject: Questions about setters
>
> Can I override a setter?  

That's the intent.

> Can I call the setter I override using super?  How exactly?

Not sure, but there might be something in the super syntax (eg, "super.x
= 10") that
would do this.  Hasn't been spec'd yet.  Not sure what AS3 does.

> > class foo {
> >   var barstate;
> >   function set bar (value) { barstate = bar }
> >   function get bar () { return barstate }
> > }
> >
> > class annotatedFoo {
> >   override function set bar (value) {
> >     note('setting bar');
> >     // how do I call my super?
> >     super['set bar'](value);
> >   }
> >   override function get bar () {
> >     note('getting bar');
> >     // how do I call my super?
> >     return super['get bar']();
> >   }
> > }
>
> Can `super` by itself mean "call next method"?  That would seem like a
> useful shortcut, and avoid the question of how you call a method with
> a space in its name.

I agree that would be convenient.

--lars

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Questions about setters

Peter Hall-4
> Not sure, but there might be something in the super syntax (eg, "super.x
> = 10") that
> would do this.  Hasn't been spec'd yet.  Not sure what AS3 does.
>


In AS3 it's like this:

override function set bar (value) {
     super.bar = value;
}




Peter
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Questions about setters

P T Withington
On 2008-07-25, at 05:52EDT, Peter Hall wrote:

>> Not sure, but there might be something in the super syntax (eg,  
>> "super.x
>> = 10") that
>> would do this.  Hasn't been spec'd yet.  Not sure what AS3 does.
>>
>
>
> In AS3 it's like this:
>
> override function set bar (value) {
>     super.bar = value;
> }

So, can I say:

override function set * (id, value) {
   note('setting ' + id + ' to ' + value);
   super[id] = value;
}

?  (It seems currently, AS3 does not allow `super[]`?)
_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Questions about setters

Brendan Eich-2
On Jul 29, 2008, at 7:53 AM, P T Withington wrote:

>> In AS3 it's like this:
>>
>> override function set bar (value) {
>>     super.bar = value;
>> }
>
> So, can I say:
>
> override function set * (id, value) {

There's no such syntax in ES4 as proposed -- the last grammar sent  
out does not produce * after set in FunctionDefinition^class.

The proposal was meta function set(id, value) {...}, and as far as I  
can see in that proposal, super[id] should work.

/be

>    note('setting ' + id + ' to ' + value);
>    super[id] = value;
> }
>
> ?  (It seems currently, AS3 does not allow `super[]`?)
> _______________________________________________
> Es4-discuss mailing list
> [hidden email]
> https://mail.mozilla.org/listinfo/es4-discuss

_______________________________________________
Es4-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es4-discuss