August 8, 2000 - The recalc() Method | WebReference

August 8, 2000 - The recalc() Method

Yehuda Shiran August 8, 2000
The recalc() Method
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript



In Column 65, Dynamic Properties, we showed how to program the Solar System. We need to trigger a recalculation because the expression we bound to the planets' parameters depends on the time in seconds passed from the initial loading of the page. The time give us a measure of the angle that the planet needs to complete. We need to find out how many seconds have passed every time interval, so we can update the angle (and the planet location) continuously. Here is the functional dependency between the angle and the time, as well as the planet's period length in days:

function angle(periodInDays, t) {

The planets' xLocation and yLocation depend on the angle. Here is the functional dependency of xLocation:

function xLocation(obj, distanceFactor, daysPerRound, t) {
  return ( + / 2) +   
	                           * fRadius * distanceOfEarth);

We trigger the evaluation by calling the setInterval() function:

intervalID = setInterval("triggerRecalculation()", frequencyOfRecalc);

where triggerRecalculation() is:

function triggerRecalculation() {
  currentTime = new Date() - timeAt0;
