Dynamic Properties: Benefits of Dynamic Properties
Dynamic Properties
Benefits of Dynamic Properties
Dynamic properties simplify and minimize the amount of code you have to use in a page. Without dynamic properties, element properties must be declared with constants only. The problem with constant properties is that they are not suitable for animation. Animation seems to be the complete opposite of constancy. In order to implement an animation in an HTML page, you had to explicitly recompute element properties over and over again, every pre-defined time interval. You can find such animation all over our columns. For example, see Column 18, JavaScript Animations, Part I and Column 19, JavaScript Animations, Part II. Using dynamic properties, you would write much less code. You still need to specify in the beginning of your code the functional dependency of element properties, and then you let JavaScript do the job for you. You don't have to touch these elements ever again. Dynamic properties do not avoid JavaScript scripting at all, but with a little coding, you make a lot of coding obsolete.
Dynamic properties are similar to a spreadsheet's implementation of a formula. A cell's value can be a constant or a formula. A formula can include references to any number of other cells in the spreadsheet. Likewise, a dynamic property can reference properties of other elements on the same document, as well as regular variables and functions.
One of the benefits of dynamic properties is that once you find the functional dependency, you don't have to monitor or maintain the page. You describe in formulas the mathematical dependency between objects, properties, and variables. This dependency is always valid and kept by the browser itself, with no scripting interruptions.
Using dynamic properties is more efficient. With constant properties, upon a certain event, you had to go over all elements on the page and update them. With dynamic properties, you figure out the exact dependencies upfront, so you never update a property without a definitive need. Continuing the spreadsheet analogy, it is much more efficient to update those cells that need to be updated according to the formulas assigned to them than go over all cells and check which cells need to be updated and then update them.
Next: How to set a dynamic property
Produced by Yehuda Shiran and Tomer Shiran
Created: July 18, 2000
Revised: July 18, 2000
URL: https://www.webreference.com/js/column65/2.html