spacer
Yehuda Shiran August 1, 2000
Lazy Evaluation
Tips: August 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

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

When implementing functional dependencies between properties, it is always a question when to trigger a recalculation following a change in one of the parameters. There are two opposite strategies. One says that you need to recalculate all parameters whenever one of the parameters or variables changes. The other one, sometimes called lazy evaluation, says that you need to compute a parameter only when you have to know its value. In such a methodology, a function is provided in case you want to force the evaluation.

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. In this example, the need to update the location of the planet is implicit. None of the statements uses the top and left parameters of the planets, but the location of the planets in the solar system is determined by these parameters. Hence, to force the update of their location, we call the recalc() method every time interval:

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

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


People who read this tip also read these tips:

Look for similar tips by subject:

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