You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@flex.apache.org by Harbs <ha...@gmail.com> on 2015/11/11 12:02:48 UTC

[FlaconJX]Multiple constructors

IFAIK, ActionScript does not have multiple constructors. I’m wondering if there’s any way to simulate multiple constructors when cross-compiling to js.

What prompted my questions is QName. QName has two different constructors. One takes a QName object, and the other takes uri and a localName. I was windering if there’s a way to get that effect with type-checking. The only way I can think of to support that would be to take a wildcard argument for the first argument (and do runtime checking) and make the second one optional.

Does anyone have better ideas?

Harbs

Re: [FlaconJX]Multiple constructors

Posted by Alex Harui <ah...@adobe.com>.
FWIW, it might be possible to teach the compiler to check for types.

FalconJX already knows how to copy the asdoc from the .AS file to the .JS
file.  However, there are currently assumptions about the format of
@params.  Any @param found in the asdoc is renamed to @asparam and the
compiler generates the @param based on the AS type used.

We could add other custom tags like @jsparam that is the format used by
Google Closure Compiler that lists the allowed types of a parameter
{Function|String} and output that instead of the AS type.  Just doing that
should then cause the Google Closure Compiler to output errors at the end
of the cross-compile.

Teaching the SWF compiler to handle @jsparam would be a lot of work.  The
SWF compiler does know about ArrayElementType metadata.  We could define
some other metadata that defines sets of types somehow.  And those could
factor into the @param in the JSDoc.  That would be a medium-sized chunk
of work.

-Alex

On 11/11/15, 10:39 AM, "Alex Harui" <ah...@adobe.com> wrote:

>The compiler sees Qname as having a single constructor with two params of
>type ‘*’.
>
>I don’t know what trick was used to get ASDoc to show two constructors.
>
>HTH,
>-Alex
>
>On 11/11/15, 9:37 AM, "Alex Harui" <ah...@adobe.com> wrote:
>
>>
>>
>>On 11/11/15, 3:02 AM, "Harbs" <ha...@gmail.com> wrote:
>>
>>>IFAIK, ActionScript does not have multiple constructors. I’m wondering
>>>if
>>>there’s any way to simulate multiple constructors when cross-compiling
>>>to
>>>js.
>>>
>>>What prompted my questions is QName. QName has two different
>>>constructors. One takes a QName object, and the other takes uri and a
>>>localName. I was windering if there’s a way to get that effect with
>>>type-checking. The only way I can think of to support that would be to
>>>take a wildcard argument for the first argument (and do runtime
>>>checking)
>>>and make the second one optional.
>>>
>>>Does anyone have better ideas?
>>
>>That’s interesting.  I’m going to spend some time trying to figure out
>>how
>>Qname is defined in PlayerGlobal.
>>
>


Re: [FlaconJX]Multiple constructors

Posted by Harbs <ha...@gmail.com>.
OK. So it’s just a bluff.

Oh well. It would be interesting if it was possible to get real multiple constructors.

No back to our regular program… ;-)

On Nov 11, 2015, at 8:39 PM, Alex Harui <ah...@adobe.com> wrote:

> The compiler sees Qname as having a single constructor with two params of
> type ‘*’.
> 
> I don’t know what trick was used to get ASDoc to show two constructors.
> 
> HTH,
> -Alex
> 
> On 11/11/15, 9:37 AM, "Alex Harui" <ah...@adobe.com> wrote:
> 
>> 
>> 
>> On 11/11/15, 3:02 AM, "Harbs" <ha...@gmail.com> wrote:
>> 
>>> IFAIK, ActionScript does not have multiple constructors. I’m wondering if
>>> there’s any way to simulate multiple constructors when cross-compiling to
>>> js.
>>> 
>>> What prompted my questions is QName. QName has two different
>>> constructors. One takes a QName object, and the other takes uri and a
>>> localName. I was windering if there’s a way to get that effect with
>>> type-checking. The only way I can think of to support that would be to
>>> take a wildcard argument for the first argument (and do runtime checking)
>>> and make the second one optional.
>>> 
>>> Does anyone have better ideas?
>> 
>> That’s interesting.  I’m going to spend some time trying to figure out how
>> Qname is defined in PlayerGlobal.
>> 
> 


Re: [FlaconJX]Multiple constructors

Posted by Alex Harui <ah...@adobe.com>.
The compiler sees Qname as having a single constructor with two params of
type ‘*’.

I don’t know what trick was used to get ASDoc to show two constructors.

HTH,
-Alex

On 11/11/15, 9:37 AM, "Alex Harui" <ah...@adobe.com> wrote:

>
>
>On 11/11/15, 3:02 AM, "Harbs" <ha...@gmail.com> wrote:
>
>>IFAIK, ActionScript does not have multiple constructors. I’m wondering if
>>there’s any way to simulate multiple constructors when cross-compiling to
>>js.
>>
>>What prompted my questions is QName. QName has two different
>>constructors. One takes a QName object, and the other takes uri and a
>>localName. I was windering if there’s a way to get that effect with
>>type-checking. The only way I can think of to support that would be to
>>take a wildcard argument for the first argument (and do runtime checking)
>>and make the second one optional.
>>
>>Does anyone have better ideas?
>
>That’s interesting.  I’m going to spend some time trying to figure out how
>Qname is defined in PlayerGlobal.
>


Re: [FlaconJX]Multiple constructors

Posted by Alex Harui <ah...@adobe.com>.

On 11/11/15, 3:02 AM, "Harbs" <ha...@gmail.com> wrote:

>IFAIK, ActionScript does not have multiple constructors. I’m wondering if
>there’s any way to simulate multiple constructors when cross-compiling to
>js.
>
>What prompted my questions is QName. QName has two different
>constructors. One takes a QName object, and the other takes uri and a
>localName. I was windering if there’s a way to get that effect with
>type-checking. The only way I can think of to support that would be to
>take a wildcard argument for the first argument (and do runtime checking)
>and make the second one optional.
>
>Does anyone have better ideas?

That’s interesting.  I’m going to spend some time trying to figure out how
Qname is defined in PlayerGlobal.