spacer

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

home / experts / javascript / column29


The Fixed-Interval Repetition Function

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business


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

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