JavaScript syntax: | - | function anId(aProp, oldVal, newVal) { someCode; return actualVal} |
Argument list: | actualVal | The value that will be placed into the property |
anId | A name for your handler function | |
aProp | A formal parameter to pass the property name in | |
newVal | A format parameter to pass the new value in | |
oldVal | A formal parameter to pass the old value in |
Your handler function is passed to the watch() method belonging to the object whose property you want to monitor.
When that property changes, your handler will be called.
You will be passed the following:
The property name
The old value
The new value
Whatever you return from this handler will be stored in the property and will become its new value. This means you can return the old value, forcing the property to be read-only. You might change the new value to something else. Perhaps you would force the value to be all uppercase regardless of how it had been specified. You may even want to display an alert to warn the operator that the property is being changed.
See also: | watch() |
Prev | Home | Next |
watch() | Up | Wave() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |