473,770 Members | 6,950 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling window.setInter val within a loop containing args

Hi All

Was trying to get this bit of code working (simplified of course)

for (i=0;i<uuid_num ;i++) {
window.setInter val(InitMap(uui dValues[i]), timePeriod);
}

Where uuid_num, uuidValues, timePeriod are defined above, along with
function InitMap.

Now, guess I have two questions,

1. Can I pass args within the window.setInter val,
2. Can I call this window.setInter val several times with different args
based on my for loop.

Or is there another approach to this that someone can see?

Regards

Shawn

Sep 28 '06 #1
3 5812
On 2006-09-28 15:06:39 +0200, "shawn" <sh*********@gm ail.comsaid:
Hi All

Was trying to get this bit of code working (simplified of course)

for (i=0;i<uuid_num ;i++) {
window.setInter val(InitMap(uui dValues[i]), timePeriod);
}

Where uuid_num, uuidValues, timePeriod are defined above, along with
function InitMap.

Now, guess I have two questions,

1. Can I pass args within the window.setInter val,
yes. But not this way.

setInterval requires a function as its first argument, not a function
call (unless it returns a function). So you can't put it the way you
dit.
However, setInterval (and setTimeout) can take additional arguments
after the function (first arg) and the interval (or timeout) delay
(second arg). These additional arguments will be passed, in the same
order, to the function.
So this should work :

for (i=0;i<uuid_num ;i++) {
window.setInter val(InitMap, timePeriod, uuidValues[i]);
}

Alternatively, setInterval can accept a string as its first argument,
and will eval() the string every tick. So you could construct a
funciton call as a string, including the arguments. But, as some are
wont to say, "eval is evil", so just forget I said anything about
passing a string to setInterval.
2. Can I call this window.setInter val several times with different args
based on my for loop.
Of course. The arguments are evaluated every time you call setInterval
(but not every time the interval'd function itself is called) so every
interval you set here will have its own uuidValue.
Or is there another approach to this that someone can see?
You should think on why you need to set so many parallel intervals,
though. Maybe a single interval could do the job more efficiently, and
you could put the for() loop inside the interval'd function ?

--
David Junger

Sep 28 '06 #2
VK

shawn wrote:
window.setInter val(InitMap(uui dValues[i]), timePeriod);
setTimeout and setInterval for the first argument take only:
a) a string to be avaluated after timePeriod
b) a reference to a function to be executed

So in the code above you do: "execute function InitMap with argument
uuidValues[i] and use the result as a reference to the function to be
executed every timePeriod".

That is not of course what you wanted: so concatenate a string to
evaluate instead:

window.setInter val("InitMap(uu idValues[" + i + "]"), timePeriod);

As a side note: setInterval is a rather dangerous stuff for operations
with unpredictable length, say involving client-server communications.
With short timePeriod and long function execution you can create
multiple function instances and make a memory mess. It is usually
better to setTimeout instead, let the function to do the stuff in peace
and set new timeout before exit.

Sep 28 '06 #3

Touffy wrote:
On 2006-09-28 15:06:39 +0200, "shawn" <sh*********@gm ail.comsaid:
Hi All

Was trying to get this bit of code working (simplified of course)

for (i=0;i<uuid_num ;i++) {
window.setInter val(InitMap(uui dValues[i]), timePeriod);
}

Where uuid_num, uuidValues, timePeriod are defined above, along with
function InitMap.

Now, guess I have two questions,

1. Can I pass args within the window.setInter val,

yes. But not this way.

setInterval requires a function as its first argument, not a function
call (unless it returns a function). So you can't put it the way you
dit.
However, setInterval (and setTimeout) can take additional arguments
after the function (first arg) and the interval (or timeout) delay
(second arg). These additional arguments will be passed, in the same
order, to the function.
So this should work :

for (i=0;i<uuid_num ;i++) {
window.setInter val(InitMap, timePeriod, uuidValues[i]);
}

Alternatively, setInterval can accept a string as its first argument,
and will eval() the string every tick. So you could construct a
funciton call as a string, including the arguments. But, as some are
wont to say, "eval is evil", so just forget I said anything about
passing a string to setInterval.
2. Can I call this window.setInter val several times with different args
based on my for loop.

Of course. The arguments are evaluated every time you call setInterval
(but not every time the interval'd function itself is called) so every
interval you set here will have its own uuidValue.
Or is there another approach to this that someone can see?

You should think on why you need to set so many parallel intervals,
though. Maybe a single interval could do the job more efficiently, and
you could put the for() loop inside the interval'd function ?

--
David Junger
Thanks David, that worked a treat. :-)

Sep 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
7794
by: Richard A. DeVenezia | last post by:
At line this.timerId = setInterval (function(){this.step()}, 100) I get error dialog Error:Object doesn't support this property or method. If I change it to this.timerId = setInterval (function(){this==window}, 100) I see true, the sad fact that 'this' is window and not an anim. What are some proper ways ? I would like to avoid
3
4424
by: Eli | last post by:
Hello all, I have just added a small piece of JavaScript code to a basic HTML page of mine. At the end of the page (after the closing </HTML>) I added: <SCRIPT LANGUAGE="JavaScript"> window.setInterval ("myFunc()", 1000); </SCRIPT> The function myFunc is as easy as you might expect, to update a text
6
15225
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I am doing wrong? Your help will be much appreciated. Thanks
4
3261
by: barry | last post by:
If The script below is exeuted from the onload="startit()" in the body tag everything works fine but when I remove the onload and try to execute by using the attributes.add from within the Page_Load the window.setInterval will not execute - there is no message but the timer never takes off. I put an alert in the startit() and it did appear so the attributes.add is working ok. Would appreciate any help thanks Private Sub...
26
5694
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized several parts of the DOM, but this does not include the window object. Thank you
4
6408
by: alexandre.brisebois | last post by:
Hi, I am using access 2003, I would like to know if there is an option to reorganize the tables in a maner that is readable, as we can do in sql sever 2000 or 2005. I have been given a database to look a and I am loosing tremendious amounts of time trying to organize it so that I could view it. Regards, Alexandre Brisebois
1
1829
by: jsavagedesign | last post by:
This is a project I have been working on lately and I keep running into problems. The idea is to be able to attaching an animation to a movie clip and call it later. Or multiple animation at once. example: on the stage you have a black box called: myClip in actionscript you type: growClip = grow(myClip); spinClip = spin(myClip); now when you call:
1
2511
by: jonahmason | last post by:
hi. a javascript newbie here in dire need of help. for the past 3 days i've been trying to get a script using setinterval to work but a part of the code, that executes after setinterval hits a certain amount of time and clearinterval is invoked, opens on a new page instead of displaying in the designated div. i've tried 2 ways of displaying the code 1. getelementbyid('designatedarea').innerhtml and 2. var x...
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10053
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8880
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3969
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.