473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

setTimeout and passing argument

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
4 14801
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Robert Mark Bram | last post by:
Howdy All! How can I make something like this work? var message = "This will appear in 10 seconds"; setTimeout ('alert(message)', 10000); Thanks for any advice!
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
29
by: Mic | last post by:
Goal: delay execution of form submit Code (Javascript + JScript ASP): <% Response.Write("<OBJECT ID='IntraLaunch' STYLE='display : none' WIDTH=0 HEIGHT=0...
18
by: Frances Del Rio | last post by:
this code is supposed to flip imgs at intervals of one second, but it flipps them much faster, it seems it flips them all in that first second, the more seconds the faster it flips them, instead of...
4
by: Ken | last post by:
Hello I am trying to change the color of a font in a text box. I have been reading about and trying various examples found it this group, but still can't get it right. Here is where I am...
2
by: Athanasius | last post by:
Could someone shed some light as to why the following setTimeout function will not work on the Mac IE5.2? It does however work on PC(Forefox,Netscape,IE) & Mac(Safari,Firefox). Here is the script,...
6
by: Brent | last post by:
Is there any obvious reason why there's no delay in the execution of setting the id.style.display when this function gets called? function Hide(divId,timeout) { var id =...
15
by: nikki_herring | last post by:
I am using setTimeout( ) to continuously call a function that randomly rotates/displays 2 images on a page. The part I need help with is the second image should rotate 3 seconds after the first...
1
by: alex.malgaroli | last post by:
Hi all. I didn't find anything on the web regarding this different behaviour I found in Firefox (v. 2) and IE (v. 6), so I'm posting it here, maybe someone will benefit from this. I have a...
19
by: liketofindoutwhy | last post by:
I did some animation using var oDiv = {}; oDiv.x = 100; oDiv.y = 100; oDiv.node = document.getElementById('divImage'); oDiv.node.style.position = "absolute"; oDiv.doAnimation = function()...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.