The linkBoth() method enables two-way data linking. The
contact object and INPUT elements are linked in both directions. When you
modify the value of the INPUT element, the contact object is also updated
automatically.
For example, the following code adds a client-side
JavaScript click handler to an HTML button element. When you click the button,
the property values of the contact object are displayed using an alert()
dialog:
The following demonstrates what happens when you change the
value of the Name INPUT element and click the Save button. Notice that the name
property of the “contact” object that the INPUT element was linked to was
updated automatically:
The above example is obviously trivially simple.
Instead of displaying the new values of the contact object with a JavaScript
alert, you can imagine instead calling a web-service to save the object to a
database. The benefit of data linking is that it enables you to focus on your
data and frees you from the mechanics of keeping your UI and data in sync.