By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,917 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,917 IT Pros & Developers. It's quick & easy.

setTimeout and passing argument

P: n/a
Hi,

I'm working with mozilla, building a little XUL app.
I have a datasource, and want to display a message
once it is loaded (datasource.loaded is true).

So, I thought to use timouts, but as the code to execute is
passed as a string, I cannot pass local variable to this code.

Anyone has a suggestion?

Thanks.

Raph

Here is what I wanted to do (but I can't pass the datasource as argument):

setTimeout(check_if_loaded(datasource), 500)
with this function:

function check_if_loaded(a_ds)
{
if (!datasource.loaded)
{
setTimeout(check_if_loaded(datasource), 500)
}
}

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Wed, 05 Nov 2003 15:55:28 +0100, Raphael Bauduin
<ra*************@be.easynet.net> wrote:
I'm working with mozilla, building a little XUL app.
I have a datasource, and want to display a message
once it is loaded (datasource.loaded is true).


I imagine it'll throw an event at such a time, catch that event, don't
test datasource.loaded is true at intervals, in fact if the technology
does require you to do this, walk away now, the technology is flawed
it should be event driven.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2

P: n/a
Jim Ley wrote:
On Wed, 05 Nov 2003 15:55:28 +0100, Raphael Bauduin
<ra*************@be.easynet.net> wrote:

I'm working with mozilla, building a little XUL app.
I have a datasource, and want to display a message
once it is loaded (datasource.loaded is true).

I imagine it'll throw an event at such a time, catch that event, don't
test datasource.loaded is true at intervals, in fact if the technology
does require you to do this, walk away now, the technology is flawed
it should be event driven.


The event thing is what I'm looking at right now, but I still wonder how
to pass arguments to code called by a timeout.

Thanks for your remark anyway ;-)

Raph


Jim.


Jul 20 '05 #3

P: n/a
"Raphael Bauduin" <ra*************@be.easynet.net> wrote in message
news:3F**************@be.easynet.net...
<snip>
The event thing is what I'm looking at right now, but I still
wonder how to pass arguments to code called by a timeout.


Some setTimeout implementations, probably including Mozilla's (as
Netscape 4 implemented it) will, when passed a function reference as
their first argument, accept arguments 3 to n as additional parameters
and pass these parameters on to the function referenced in the first
argument when it is called.

Richard.
Jul 20 '05 #4

P: n/a
Raphael Bauduin <ra*************@be.easynet.net> wrote in message news:<3f**********************@feed0.news.be.easyn et.net>...
Hi,

I'm working with mozilla, building a little XUL app.
I have a datasource, and want to display a message
once it is loaded (datasource.loaded is true).

So, I thought to use timouts, but as the code to execute is
passed as a string, I cannot pass local variable to this code.

Anyone has a suggestion?


There are more than a few caveats to using setTimeout. Some reading
material:

http://devedge.netscape.com/toolbox/.../CCallWrapper/
http://www.intranetjournal.com/artic...0010/js11.html
http://w3future.com/html/stories/callbacks.xml
http://blogs.gotdotnet.com/ericli/co...3-3bbcc2df240e
http://jsindex.com (search for 'multi-threading')

In general, you can create an anonymous function (closure) without
arguments that retains access to a local variable (like datasource)
from the enclosing lexical scope. The anonymous function can pass the
variable as a parameter to the function of your choice.

Note that Konqueror has (had?) a problem with anonymous functions and
setTimeout. Workarounds:

http://www.mojavelinux.com/forum/vie...387ab3c1d8dbcb
http://autometa.com/DOM
--
Rich Persaud | weblog > http://dotPeople.com
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.