The getting and setting of values is very common in JavaScript page functions. Whether it is to validate user input, assemble input values to service calls, or generate messages and summaries, page code often reads and writes component values. It is best practice to use setters and getters whenever available. Getters and setters are the functions that get and set values on an object. They almost always use set
and get
in their name, such as getDataValue()
, setCaption()
, and setDataValue()
. The use of getters, and especially setters, instead of performing an assignment ensures that change notifications and any required refreshing of the component takes place.
Take, for example, a label named labelTitle
. We might be tempted to assign the caption to a value as shown in the following line of code:
this.labelTitle.caption="Welcome";
Now, what happens if we use the preceding line of code to assign a new value to a caption via the console? Well, nothing. We will not see...