Object.watch()

JavaScript 1.2+ Nav4+, NES3+ Syntax

							object.watch(prop,
							function)

Description

The watch() method of the Object object is used to watch for the event in which a property gets assigned a value. When the assignment is made, a user defined function is executed. The method itself takes the property to watch, prop, and the function to call, func, when the event occurs.

Example

Listing 6.199 shows how the watch() method is used.

Listing 6.199 Example of the watch() Method
 <html> <body> <title>Example of the watch method</title> <script language="JavaScript"> <!––Hide // function informs the user when the tmp variable is changed. function inform(){ document.write("Tmp variable changed from 1 to 3"); } // declare a tmp variable ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.