Questions about setters
-----Original Message----- From: es4-discuss-bounces at mozilla.org [mailto:es4-discuss- bounces at mozilla.org] On Behalf Of P T Withington Sent: 24. juli 2008 22:30 To: es4-discuss at mozilla.org 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'; } 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.
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
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[]
?)
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.
Can I override a setter? Can I call the setter I override using
super? How exactly?
Can
super
by itself mean "call next method"? That would seem like auseful shortcut, and avoid the question of how you call a method with
a space in its name.