Solution for trouble with super() and variable arguments

8 views
Skip to first unread message

Robert Penner

unread,
Jan 18, 2010, 1:02:56 AM1/18/10
to as3-signals
Because AS3 doesn't allow super.apply, it can be difficult to subclass
Signal. But I just committed a solution where Signal supports passing
an array from the subclass.

In other words, because this isn't allowed in AS3--

public function MySignal(...valueClasses)
{
super.apply(null, valueClasses);
}

--Signal now allows you to do this:

public function MySignal(...valueClasses)
{
super(valueClasses);
}

I also moved constructor logic out to a protected function
setValueClasses(), which can be overridden or called with super.

Here's the commit:

http://github.com/robertpenner/as3-signals/commit/a4b2a6b6478a22a341f9ffcd698f086f9d374465

I plan to apply this to DeluxeSignal as well.


On Mon, Dec 7, 2009 at 3:15 PM, Robert Penner <in...@robertpenner.com> wrote:
>> class MySignal{
>>         public function MySignal(...valueClasses){
>>                 super([MyForcedClass1,MyForcedClass2].concat(valueClasses));
>>         }}
>
> That doesn't look like it will work, because you're only passing one
> argument, an array, to super().
>
> I'm not sure if you can do super.apply(null,
> [MyForcedClass1,MyForcedClass2].concat(valueClasses)).
>
> Robert
>
> On Dec 3, 3:21 pm, karfau <co...@karfau.de> wrote:
>> Well maybe just forget about the question about the optional
>> parameters in constructors...
>>
>> One way could be to force two parameters for the functions and allow
>> additional ones by using the following syntax in an extending Class:
>>
>> class MySignal{
>>         public function MySignal(...valueClasses){
>>                 super([MyForcedClass1,MyForcedClass2].concat(valueClasses));
>>         }}
>>
>> if ever nessesary.
>>
>> So another wow, looking forward to use this, as I always felt creepy
>> with all those const Strings all over the place that needed to be
>> somehow unique.
>>
>> karfau
>

Reply all
Reply to author
Forward
0 new messages