flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Harui <aha...@adobe.com>
Subject Re: [FALCONJX][FLEXJS] "as" keyword handling
Date Fri, 08 Jan 2016 01:32:41 GMT


On 1/7/16, 5:24 PM, "Andy Dufilie" <andy.dufilie@gmail.com> wrote:

>On Thu, Jan 7, 2016 at 4:55 PM, Alex Harui <aharui@adobe.com> wrote:
>
>> How many of you use the "as" keyword as part of a test?
>
>
>I have a huge code base and I use "as" / "is" everywhere (
>https://github.com/WeaveTeam/Weave). My code depends on it behaving the
>same way it does in ActionScript.  IMO, being able to easily check if an
>object extends or implements a class/interface is a huge advantage AS has
>over JS.
>
>
>> The reason I'm asking is because the use of "as" as become a negative
>> factor in several cases:
>> 1) In JS, it results in a function call
>>
>
>Yes. In ActionScript, using "as" actually sped up the code in certain
>situations, but in JS it is a performance hit.  This is a very common
>pattern in my code:
>
>if (obj is Thing1)
>    (obj as Thing1).foo(a,b);
>else if (obj is Thing2)
>    (obj as Thing2).bar(x,y);


There are no plans to change "is", just "as".  Are you using "as" as a
test or just "is".  In the example above, you are using "as" just to make
the compiler happy.


>I see "is" and "as" as highly useful features, and I think it would be a
>mistake to make the code cross-compile into something that behaves
>differently by default.  IMO if cross-compiled code behaves differently
>than the original then it's being mangled and can't be trusted.

That's the root of my question: how many folks us "as" to actually convert
data vs just make the compiler happy.  Again, no plans to change "is".

>
>A related issue is when setting a typed variable or passing in a parameter
>to a function, it will do type coercion automatically in AS but that
>behavior is lost when cross-compiling to JS.  For example, I have
>situations like this where I now have to add manual type casting, and I
>wish the compiler would do that automatically:
>
>var str:String = value_which_may_be_a_number;

What error are you getting?  I thought the auto-conversion worked for both
JS and AS.

-Alex

Mime
View raw message