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

# August 8, 2000 - The recalc() Method

 August 8, 2000The recalc() Method Tips: August 2000 Yehuda Shiran, Ph.D.Doc JavaScript
In JavaScript, you can force a recomputation by calling the `Document` Object's `recalc()` method:

``document.recalc(true);``

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) {
return ((t / seconds2daysFactor) / periodInDays) % (2 * Math.PI);
}``````

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

``````function xLocation(obj, distanceFactor, daysPerRound, t) {
return (obj.style.pixelLeft + obj.style.pixelWidth / 2) +
Math.round(Math.cos(angle(daysPerRound, t)) * distanceFactor
}``````

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

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

where `triggerRecalculation()` is:

``````function triggerRecalculation() {
currentTime = new Date() - timeAt0;
document.recalc(true);
}``````

For more on Dynamic Properties, go to Column 65, Dynamic Properties.