List Info

Thread: setTimeout() problems




setTimeout() problems
user name
2006-05-24 15:31:01
On 5/24/06, Premshree Pillai <premshree.pillaigmail.com> wrote:
> On 5/24/06, Jonathan Buchanan <jonathan.buchanangmail.com> wrote:
>    var arr = new Array("foo",
"bar", "baz");
>    for (var i=0; i<arr.length; i++) {
>       window.setTimeout(
>          function(arg) { return function() {
alert(arg); }; }(arr[i]),
>          1000
>       );
>    }

Using GM 0.6.4 and FF 1.5.0.3, this does 3 alerts in series
(foo, bar,
baz) for me.

Did I misunderstand the expected behavior?   Is this exact
code not
working for you, or was this intended as a simplified
example?
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
setTimeout() problems
user name
2006-05-24 15:49:47
On 5/24/06, Jeremy Dunck <jdunckgmail.com> wrote:
> On 5/24/06, Premshree Pillai <premshree.pillaigmail.com> wrote:
> > On 5/24/06, Jonathan Buchanan
<jonathan.buchanangmail.com> wrote:
> >    var arr = new Array("foo",
"bar", "baz");
> >    for (var i=0; i<arr.length; i++) {
> >       window.setTimeout(
> >          function(arg) { return function() {
alert(arg); }; }(arr[i]),
> >          1000
> >       );
> >    }
>
> Using GM 0.6.4 and FF 1.5.0.3, this does 3 alerts in
series (foo, bar,
> baz) for me.
>
> Did I misunderstand the expected behavior?   Is this
exact code not
> working for you, or was this intended as a simplified
example?

What I'm hoping for is to call the anonymous function
within the loop
periodically -- every 5 seconds or so. So what I want is the
first
alert, followed by a pause (1000 ms, in this case), followed
by
another alert, and so on.

I'm definitely missing something. :/

Premshree
_______________________________________________
Greasemonkey mailing list
Greasemonkeymozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )