Mozilla and setInterval

  • Thread starter Richard A. DeVenezia
  • Start date
R

Richard A. DeVenezia

Is some future Mozilla going to support setInterval ( <function:function>,
<interval:number> ) ?
Right now it seems to be simply setInterval ( <function-text:string>,
<interval:number> )
 
R

Richard Cornford

Richard A. DeVenezia said:
Is some future Mozilla going to support setInterval
( <function:function>, <interval:number> ) ?
Right now it seems to be simply setInterval
( <function-text:string>, <interval:number> )

Mozilla does support passing a function reference as the first argument
to both setTimeout and setInterval.

A compatibility trick with setTimeout and setInterval is to use
exclusively function references and provide the function referred to
with its own toString method that returns a string of JavaScript source
code that would call the function via some global identifier. If the
setTimout/Interval function implementation does not support function
reference arguments it type-converts the function into the expected
string by calling its toString method. Allowing the more efficient
function references to be used where supported and providing a fallback
when unsupported. (I have posted a number of examples over the last 3 or
4 months so groups.google.com search comp.lang.javascript for my posts
(and some of Yep's) with the keyword setTimeout (and possibly toString)
to see example code).

Richard.
 
L

Lasse Reichstein Nielsen

Richard A. DeVenezia said:
Is some future Mozilla going to support setInterval ( <function:function>,
<interval:number> ) ?
Right now it seems to be simply setInterval ( <function-text:string>,
<interval:number> )

It works fine with a function.

Just try
setInterval(function(){alert("foo");},2000);
(and be ready to close the window in one of the breaks).

/L
 
L

Laurent Bugnion, GalaSoft

Hi,
It works fine with a function.

Just try
setInterval(function(){alert("foo");},2000);
(and be ready to close the window in one of the breaks).

/L

Why not make it more challenging?
setInterval(function(){alert("foo");},20);

;-)
 
R

Richard A. DeVenezia

Lasse Reichstein Nielsen said:
It works fine with a function.

Just try
setInterval(function(){alert("foo");},2000);
(and be ready to close the window in one of the breaks).

/L

This is a 'simplified' version of what I thought wasn't working, but dangit,
it works.

function foo (N1) {
function bar (N2) {
this.liftOffIn (N2)
}
bar.prototype.liftOffIn = function (N3) {
this.N = N3
var thisobj = this
this.timerId = setInterval ( function () { thisobj.count() }, 1250 )
}
bar.prototype.count = function () {
if (this.N<1) {
alert ('Done')
clearInterval (this.timerId)
return
}
alert (this.N)
this.N--
}
new bar (N1)
}

foo (5)
 
R

Richard A. DeVenezia

Yup, it sure does! The problem was this

in Mozilla
element.style.backgroundColor = '#FFFF00';
alert (element.style.backgroundColor ); // shows rgb (255,255,0)

Seeing how my function scheduled to run expected #rrggbb when reading the
color back, it was destined to break when it came across the rgb()
translation Mozilla so nicely did.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top