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).

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++) {
        }

   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

-- 
Oetiker+Partner AG              tel: +41 62 775 99 03 (direct)
Fritz Zaucker                        +41 62 775 99 00 (switch board)
Aarweg 15                            +41 79 675 06 30 (mobile)
CH-4600 Olten                   fax: +41 62 775 99 05
Schweiz                         web: www.oetiker.ch


------------------------------------------------------------------------------
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