incubator-flex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Schmalle <apa...@teotigraphix.com>
Subject Re: [FalconJx] Package down to Expression production; JSGoogEmiter prototype
Date Thu, 27 Dec 2012 10:33:04 GMT
Well,

If you look at my commits, I already have this implemented in JSGoogEmitter.

From;

function method1(p1:int, p2:int, p3:int = 3, p4:int = 4):int{
     return p1 + p2 + p3 + p4;
}


To;

          foo.bar.A.method1 = function(p1, p2, p3, p4) {
             if (arguments.length < 4) {
                 if (arguments.length < 3) {
                     p3 = 3;
                 }
                 p4 = 4;
             }
             return p1 + p2 + p3 + p4;
          }


Mike

Quoting Frank Wienberg <frank@jangaroo.net>:

> On Sun, Dec 23, 2012 at 11:32 AM, Erik de Bruin <erik@ixsoftware.nl> wrote:
>
>> My personal preference for optional arguments goes to:
>>
>> optArg = optArg !== 'undefined' ? optArg : defaultValue;
>>
>
> Hi Erik,
>
> the way we implement this should not change ActionScript language
> semantics. Sorry, but this is not a question of personal preference.
> As explained in detail in this blog
> post<http://blog.jangaroo.net/2012/01/simulating-actionscript-parameter.html>,
> ActionScript does *not* replace undefined parameters by their default
> values, but it only uses the default values when less actual parameters are
> given in the call. Thus, the generated code has to check arguments.length.
> The blog post discusses some optimizations (performance, code size), but if
> you want a solution that is easy to generate (one default parameter => one
> line of generated code) *and* leads to the correct semantics, please use
>
>   if (arguments.length < optArgIndex) optArg = defaultValue;
>
> I'm a big fan of ?: expressions, but in this case, an if-statement is
> clearly the better choice, as "else", the parameter value should stay as-is
> (and not be assigned to itself).
> Optimization: When there are multiple optional arguments, it is obvious
> that the corresponding if-statements should be sorted by decreasing
> argument index and then nested, because it is obsolete to check for
> arguments.length
> < 4 if you already know that arguments.length < 3. But I agree that we can
> add this optimization later. I just would like to see us get the
> *semantics*right in the first go.
>
> Greetings
> -Frank-
>

-- 
Michael Schmalle - Teoti Graphix, LLC
http://www.teotigraphix.com
http://blog.teotigraphix.com


Mime
View raw message