Introducing DOCJSLIB 3.0, The Fixed-Interval Repetition Function - Doc JavaScript | WebReference

Introducing DOCJSLIB 3.0, The Fixed-Interval Repetition Function - Doc JavaScript


The Fixed-Interval Repetition Function

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


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

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