spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / javascript / column29


The Fixed-Interval Repetition Function

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

DOCJSLIB Version 3.0 introduces the first in a time-related series of functions. Previous versions of DOCJSLIB supported user events such as mouse clicking, but none of the library's functions had a notion of clock time. We added the doThisCommandEveryIntervalMS() function to DOCJSLIB to make it easier for you to use this time-related functionality. Both Netscape Navigator and Internet Explorer use the same method for implementing this capability (setInterval()), but the name of the method is not that intuitive and calls for a more mnemonic wrapper. DOCJSLIB Version 3.0 does exactly that.

The name of the function explains exactly what it does: it executes a given JavaScript command every a given fixed-length time interval:

function docjslib_doThisCommandEveryIntervalMS(command, interval) {
  setInterval(eval('"' + command + '"'), interval);
}

The specified command can be a single JavaScript method call, or a series of commands enclosed within a pair of quotes. In our Watermarks implementation, the command is a call to the waterMark() function:

docjslib_doThisCommandEveryIntervalMS("waterMark()", 100);

Suppose we want to print a debug message every time waterMark() is called. The command parameter above would be 'waterMark(); alert("a call to waterMark")'.

The second parameter of the doThisCommandEveryIntervalMS() function is the time interval. Notice that it is should be specified in milliseconds. This is the reason we appended "MS" to the end of the function name.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint


Created: November 9, 1998
Revised: November 9, 1998

URL: http://www.webreference.com/js/column29/interval.html