Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > question about Timers @ stuff............

Reply
Thread Tools

question about Timers @ stuff............

 
 
RobG
Guest
Posts: n/a
 
      05-18-2007
On May 18, 9:47 am, (E-Mail Removed) wrote:
> > I was being generous. In my experience, I believe it's 100%.
> > In other words, it's very nearly certain that you can do what
> > you need with setTimeout(), but don't know how.

>
> > --

>
> Sorry Lee, you are, and for clarification, I cannot run/execute
> setTimeout(), in a real pure technical sense, IE just ignores it.....
> it might be a security issue, but I work in a real integrated legacy
> environment, and really this is a particularly minor thing affecting
> about half dozen problem areas in some new code I am integrating that
> uses setTimeout().


Your users must have very old versions of IE. According to a Richard
Cornford post (link below) version 4 doesn't support function
references, it wants a string.

There is an interesting thread regarding it titled "small function
doesnt work in IE", link below. Richard Cornford's answer is copied
below my signature, check for auto-wrapping (though I think Richard
was pretty thorough with manually wrapping it).

<URL:
http://groups.google.com.au/group/co...32dff72df262c0
>



> <script>
>
> var hold_timer=5000;milliseconds
>
> do (pause in a 5 sec loop based on hold_timer) {


Javascript doesn't have a pause function. You must use either
setTimeout or setInterval.


--
Rob

Erwin Moller wrote in message

<3ebbb857$0$49100$(E-Mail Removed)4all.nl>...
<snip>

>..., it is solved now I guess.


Hopefully, but your proposed solution used the javascript pseudo
protocol which is not something that the regulars on this group ever
recommend (with the possible exception of Lee's pop-up window timing
solution application of it). The group's FAQ (section 4.24) advises
against its use in general terms and DU recently proposed that the FAQ
entry's wording should be modified to go provide some explanation of
the
many undesirable and often browser type, versions and/or operating
system dependent side effects of its use.

One of its (many) problems is that to the browser it represents
navigation, putting the current page into a waiting state in which the
browser stops performing resource hungry tasks. The most obvious
manifestation of which is that animated GIFs stop playing, but other
facilities also disappear with its first invocation.

Mac IE 5 suffers really badly from side effects of the use of the
javascript pseudo protocol, but it seems to have some undesirable
effects on every browser.

<snip>

>I use Konquerer 3.0.3-14, so I can test it if you want.


>But.... I always pass a string (with a function)
>to the setTimeout....


The string argument versions is more widely supported but most of the
modern browsers will accept function references as the first argument.
The string argument version must invoke the eval function in order to
execute the code in the string, which would be slower than invoking a
function by reference. Also, Avant Go and possibly other small,
embedded
browsers do not have the resources to implement the eval function and
so
they cannot use the string argument version. I don't know whether they
support the function reference version or just don't implement a
setTimeout function at all (it is extremely hard to get documentation
on
most embedded browsers).

>I do not know how to create a reference to a function.


Given a function:-

function myFunction(){
...

}

- the identifier - myFunction - is a function reference. That is, it
is
a property of the global object that holds a reference to the function
object that was created when the function definition above was
interpreted.

When calling the function as - myFunciton(); - the brackets '()' might
best be viewed as an operator (a function execution operator) that
operates on the function referred to by the value in the property -
myFunction - . So, if you can append '()' (possibly with arguments) to
an identifier and execute a function, then that identifier _is_ a
reference to a function (a function object in JavaScript).

As the properties that refer to functions contain references to
function
objects the references can be copied:-

var copyOfFuncRef = myFunciton;

- leaves both properties - myFunction - and - copyOfFuncRef - holding
references to the same function object. And that function object can
now
be called as - copyOfFuncRef() - .

>But if you post a sample I'll be happy to test it for you.


The reason for my interest is that I am aiming at maximum efficiency
(the function reference version) and maximum compatibility (fall-back
to
the string argument version if that is all that is available) and I
want
to do this without having to go through a battery of tests like the
ones
I will post below.

I have noticed that if IE 4 or Opera 5 are passed a function reference
as the first argument to setTimeout (which they do not support) they
type convert it into a string. To do the type conversion they call the
function's toString method. toString is defined on the
Function.prototype but if the function object in question is provided
with its own toString method it will override the method on the
prototype.

My plan is to provide any functions that are passed as references to
setTimeout with toString methods that will return a string that would
call the function anyway. All of the (20 odd) browsers/versions that I
have accept the function reference argument except IE 4 an Opera 5 and
those two happily type-convert the function reference to a string
using
its toString method.

I have not been able to test with Konquerer 3. If it accepts function
reference arguments my plan can go ahead, if it will type-convert the
reference with the function's toString method I am still in business.
If
it only accepts string arguments and will not type convert a function
reference then I will have to adopt testing and code branching
strategy
instead (much more code).

It may seem wasteful to provide any function that is to be used with
setTimeout with an additional toString method but that can be done for
just one setTimeout-setting function as I described in the thread with
the subject 'closures, what are they good for?'.

The following HTML should test setTimout and setInterval and alert the
results about half a second after the onload event. The alert should
say
if each function supports function reference arguments, string
arguments
and, if only string arguments, whether Konquerer is willing to type
convert function references into strings.

(sorry it is not shorter but I may as well find out once and for all.
I
should have handled the line wrapping (at 72 characters) so that the
page can just be cut-n-pasted from your newsreader.)

<html>
<head>
<title>setTimeout tests</title>
<script type="text/javascript">
var setTmExists = (typeof window.setTimeout != 'undefined');
var setInExists = (typeof window.setInterval != 'undefined');
var setTmString = false;
var setTmString2 = false;
var setTmFunc = false;
var setInString = false;
var setInString2 = false;
var setInFunc = false;
var testTimer,testTimer2;

function testSetTm(){
setTmFunc = true;
setTimeout('setTmString = true;', 1);
}

testSetTm.toString = function(){
return 'setTmString = true;';

}

function testSetIn(){
clearInterval(testTimer);
setInFunc = true;
testTimer = setInterval(
'setInString = true;clearInterval(testTimer);', 1);
}

testSetIn.toString = function(){
return 'setInString = true;clearInterval(testTimer);';

}

if(setTmExists){
setTimeout('setTmString2 = true;', 1);
setTimeout(testSetTm, 1);
}

if(setInExists){
testTimer2 = setInterval(
'setInString2 = true;clearInterval(testTimer2);', 1);
testTimer = setInterval(testSetIn, 1);

}

function checkTest(){
var st = 'The window.setTimeout function '+
(setTmExists?'exists':'does not exist')+'\n';
if(setTmExists){
st += '\tstring arguments are '+
(setTmString?'':'not ')+'supported\n\tfunction arguments are '+
((setTmFunc||setTmString2)?'':'not ')+'supported\n';
if((!setTmFunc)&&(!setTmString)&&(setTmString2)){
st +=
'\tfunction arguments are not type-converted by setTimeout\n';
}
}
st += '\nThe window.setInterval function '+
(setInExists?'exists':'does not exist')+'\n';
if(setInExists){
st += '\tstring arguments are '+
(setInString?'':'not ')+'supported\n\tfunction arguments are '+
((setInFunc||setInString2)?'':'not ')+'supported\n';
if((!setInFunc)&&(!setInString)&&(setInString2)){
st +=
'\tfunction arguments are not type-converted by setInterval\n';
}
}
alert(st);
}

checkTest.toString = function(){
return 'checkTest();';
}

</script>
</head>
<body onload="setTimeout('checkTest()', 400);">
<p>setTimeout tests.
</p>
</body>
</html>

Thanks,

Richard.

 
Reply With Quote
 
 
 
 
rebeccatre@gmail.com
Guest
Posts: n/a
 
      05-18-2007
<sniiiipporinie>

None of these thoughtful examples worked, mainly because they use
setTimeout to achieve delay. Can some other weird out of box thinking
achieve reliable delay/then do ()function step?

Thank you a million ways.



 
Reply With Quote
 
 
 
 
-Lost
Guest
Posts: n/a
 
      05-18-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> <sniiiipporinie>
>
> None of these thoughtful examples worked, mainly because they use
> setTimeout to achieve delay. Can some other weird out of box thinking
> achieve reliable delay/then do ()function step?


What version of Internet Explorer are you using?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
 
Reply With Quote
 
rebeccatre@gmail.com
Guest
Posts: n/a
 
      05-18-2007
On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > <sniiiipporinie>

>
> > None of these thoughtful examples worked, mainly because they use
> > setTimeout to achieve delay. Can some other weird out of box thinking
> > achieve reliable delay/then do ()function step?

>
> What version of Internet Explorer are you using?
>
> --
> -Lost
> Remove the extra words to reply by e-mail. Don't e-mail me. I am
> kidding. No I am not.


Under fixed 6.0 basic js standards minimum thx!!

 
Reply With Quote
 
-Lost
Guest
Posts: n/a
 
      05-18-2007
(E-Mail Removed) wrote:
> On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>>> <sniiiipporinie>
>>> None of these thoughtful examples worked, mainly because they use
>>> setTimeout to achieve delay. Can some other weird out of box thinking
>>> achieve reliable delay/then do ()function step?

>> What version of Internet Explorer are you using?
>>

>
> Under fixed 6.0 basic js standards minimum thx!!


Um, my Internet Explorer 6 runs setTimeout() just fine.

Can you show us the page where this is failing?

Did you ever try Lee's example, just to see if a very simple call worked?

The more of an attempt you make, the better solution others can provide.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
 
Reply With Quote
 
rebeccatre@gmail.com
Guest
Posts: n/a
 
      05-18-2007
On May 17, 10:04 pm, -Lost <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) wrote:
> >>> <sniiiipporinie>
> >>> None of these thoughtful examples worked, mainly because they use
> >>> setTimeout to achieve delay. Can some other weird out of box thinking
> >>> achieve reliable delay/then do ()function step?
> >> What version of Internet Explorer are you using?

>
> > Under fixed 6.0 basic js standards minimum thx!!

>
> Um, my Internet Explorer 6 runs setTimeout() just fine.
>
> Can you show us the page where this is failing?
>
> Did you ever try Lee's example, just to see if a very simple call worked?
>
> The more of an attempt you make, the better solution others can provide.
>
> --
> -Lost
> Remove the extra words to reply by e-mail. Don't e-mail me. I am
> kidding. No I am not.


Lost, just seperating the theory from the request, can such
theoretical delay to execute functions, be created without expressly
using the command setTimeout()?

 
Reply With Quote
 
rebeccatre@gmail.com
Guest
Posts: n/a
 
      05-18-2007
On May 17, 10:44 pm, -Lost <(E-Mail Removed)> wrote:
> (E-Mail Removed) wrote:
> > On May 17, 10:04 pm, -Lost <(E-Mail Removed)> wrote:
> >> (E-Mail Removed) wrote:
> >>> On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
> >>>> (E-Mail Removed) wrote:
> >>>>> <sniiiipporinie>
> >>>>> None of these thoughtful examples worked, mainly because they use
> >>>>> setTimeout to achieve delay. Can some other weird out of box thinking
> >>>>> achieve reliable delay/then do ()function step?
> >>>> What version of Internet Explorer are you using?
> >>> Under fixed 6.0 basic js standards minimum thx!!
> >> Um, my Internet Explorer 6 runs setTimeout() just fine.

>
> >> Can you show us the page where this is failing?

>
> >> Did you ever try Lee's example, just to see if a very simple call worked?

>
> >> The more of an attempt you make, the better solution others can provide.

>
> > Lost, just seperating the theory from the request, can such
> > theoretical delay to execute functions, be created without expressly
> > using the command setTimeout()?

>
> Alright, separating both theory and logic:
>
> 1. Setup a never ending loop that checks if Date returns a value at or
> beyond the length of your "delay."
> 2. Use setInterval once by immediately clearing it after a certain
> amount of executions. 1, in this case.
>
> --
> -Lost
> Remove the extra words to reply by e-mail. Don't e-mail me. I am
> kidding. No I am not.


1. is better, as setInterval seems to not function too, so we are left
with comparing system dates.... can you super plz. show starting
example, that shall execute alert('green'); after declared input wait
of 5 seconds?

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      05-18-2007
On May 18, 1:32 pm, (E-Mail Removed) wrote:
> On May 17, 10:04 pm, -Lost <(E-Mail Removed)> wrote:
> > (E-Mail Removed) wrote:
> > > On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
> > >> (E-Mail Removed) wrote:
> > >>> None of these thoughtful examples worked, mainly because they use
> > >>> setTimeout to achieve delay. Can some other weird out of box thinking
> > >>> achieve reliable delay/then do ()function step?
> > >> What version of Internet Explorer are you using?

>
> > > Under fixed 6.0 basic js standards minimum thx!!

>
> > Um, my Internet Explorer 6 runs setTimeout() just fine.

>
> > Can you show us the page where this is failing?

>
> > Did you ever try Lee's example, just to see if a very simple call worked?

>
> > The more of an attempt you make, the better solution others can provide.

>
> Lost, just seperating the theory from the request, can such
> theoretical delay to execute functions, be created without expressly
> using the command setTimeout()?


Yes, using setInterval. Where setTimout runs once, setInterval runs
regularly at the interval you set. So you could put commands to be
run in a queue (say using an object to store them), then have
setInterval wake up at say 5 second intervals , execute whatever is in
the queue (or not if a particular item's time isn't up yet), then
remove executed functions from the queue.

This strategy is employed by those who wish to construct their own
system of calling multiple handlers for an event and don't trust
browsers to run them in the right sequence, or who want to
conditionally execute some handlers based on the outcome of other
handlers. Most javascript libraries include some kind of queue
management.

There is no other way to run a command at some specified time or
interval or to insert a pause/wait/sleep in a running function.


--
Rob

 
Reply With Quote
 
Lee
Guest
Posts: n/a
 
      05-18-2007
(E-Mail Removed) said:
>
>On May 17, 10:44 pm, -Lost <(E-Mail Removed)> wrote:
>> (E-Mail Removed) wrote:
>> > On May 17, 10:04 pm, -Lost <(E-Mail Removed)> wrote:
>> >> (E-Mail Removed) wrote:
>> >>> On May 17, 8:59 pm, -Lost <(E-Mail Removed)> wrote:
>> >>>> (E-Mail Removed) wrote:
>> >>>>> <sniiiipporinie>
>> >>>>> None of these thoughtful examples worked, mainly because they use
>> >>>>> setTimeout to achieve delay. Can some other weird out of box thinking
>> >>>>> achieve reliable delay/then do ()function step?
>> >>>> What version of Internet Explorer are you using?
>> >>> Under fixed 6.0 basic js standards minimum thx!!
>> >> Um, my Internet Explorer 6 runs setTimeout() just fine.

>>
>> >> Can you show us the page where this is failing?

>>
>> >> Did you ever try Lee's example, just to see if a very simple call worked?

>>
>> >> The more of an attempt you make, the better solution others can provide.

>>
>> > Lost, just seperating the theory from the request, can such
>> > theoretical delay to execute functions, be created without expressly
>> > using the command setTimeout()?

>>
>> Alright, separating both theory and logic:
>>
>> 1. Setup a never ending loop that checks if Date returns a value at or
>> beyond the length of your "delay."
>> 2. Use setInterval once by immediately clearing it after a certain
>> amount of executions. 1, in this case.
>>
>> --
>> -Lost
>> Remove the extra words to reply by e-mail. Don't e-mail me. I am
>> kidding. No I am not.

>
>1. is better, as setInterval seems to not function too, so we are left
>with comparing system dates.... can you super plz. show starting
>example, that shall execute alert('green'); after declared input wait
>of 5 seconds?


It would be irresponsible to show you how to code a loop that
consumes the entire CPU until you've at least shown that you've
been attempting to use the proper methods correctly.

If you can't figure out how to code a loop that compares the
time, I certainly don't believe you've been able to figure
out the correct way to use setTimeout() and/or setInterval().

Did you try running my example code?


--

 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      05-18-2007
In comp.lang.javascript message <(E-Mail Removed)
oglegroups.com>, Thu, 17 May 2007 11:02:01, (E-Mail Removed) posted:
>hi can Variant archiving setTimout('.. capability be done without
>using it?


If your mother tongue is of non-obscure West European mainland origin,
please write in it. For any such language, there is almost certainly
someone here who can read it. You can add an 'English' translation to
confuse the monoglots.

--
(c) John Stockton, Surrey, UK. ???@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
In MS OE, choose Tools, Options, Send; select Plain Text for News and E-mail.
Don't quote more than is needed, and respond after each quoted part.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling all old-timers DOS2, BASIC v1 question Jack B. Pollack Computer Support 8 12-13-2006 05:36 PM
Timers spf R Siffredi Cisco 1 10-31-2005 05:11 PM
Quick newbie Java programming question (idle, timers) Starwynd Java 1 11-23-2003 09:10 AM
System.Timers.Timer vs. System.Threading.Timer Kelsang Wangchuk ASP .Net 0 07-31-2003 04:28 PM
Timers in application web programming Stephen Inkpen ASP .Net 1 07-16-2003 02:12 AM



Advertisments