Hi

Fritz Zaucker wrote:
> Hi Martin,
> 
> On Tue, 20 Jan 2009, Martin wrote:
> 
>> I think I found it in my source code. It's a shame.
>>
>> What I was doing in my callback function (called from rpc.callAsync) was:
>>
>> for (i=0;i<result.lenght;i++)
>>
>> and it should have been
>>
>> for (var i=0;i<result.lenght;i++)
>>
>> I think I've been rewriting some global variable called "i" (which
>> could've been part of some class definition or something).

Ouch, the "var i" thing was a tough thing to spot i guess. A variable
must have gotten the name "i" in the optimized code, whereas it worked
in the source.


> two comments (unrelated to your error):
> 
> - var in JS is working on a function level, NOT on block-level (as e.g. in
>    Perl). So in case you have a variable i outside the for loop but inside
>    the same function, you'll still overwriting it, even with var in the for
>    loop:
> 
>    function test() {
>       var i=5;
> 
>       for (var i=0; i<10; i++) {
>       }
> 
>       alert('i='+i);
>    }
> 
>    will give i=9
> 
>    Very ugly indeed.
> 
> - Apparently, in JS result.length in your look will be evaluated in every
>    iteration. Therefore you should move it outside the loop:
> 
>       var i;
>       var len=result.length;
>       for (i=0; i<len; i++) {
>       }

For the sake of compactness, you could also write:

for(var i = 0, len = result.length; i < len; i++){

}

Which does exactly the same thing as the method described above.


>    There also seem to be other (rather unexpected) issues with loop
>    performance, see e.g.
>    http://www.webreference.com/programming/optimize/speedup/chap10/3/2.html
> 
>    Note: I did not benchmark these optimisations myself yet ...
> 
>    In any case, they probably really matter only for loops with many
>    iterations (or ones being called frequently).
> 
> Cheers,
> Fritz
> 

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel

Reply via email to