Jump to content

someObj.watch()


Jesdisciple

Recommended Posts

<html>	<head>		<script type="text/javascript">			function main(){				window.watched = 0;				window.watch(					'watched',					function(id, oldVal, newVal){						alert('You changed ' + id + ' from ' + oldVal + ' to ' + newVal + '!');					}				);				window.watched = 1;			}		</script>	</head>	<body onLoad="main();">	</body></html>

My discovery of this function began with typing Object. in Dreamweaver 2004, and Object.watch(prop, callback, userData) being suggested. Strangely, the function doesn't seem to take 3 arguments, but only 2 (one of which is a function with 3). Am I missing something, or was Macromedia just wrong?When I try to use this function as described by Mozilla, Opera rejects it with:

[Error:name: TypeErrormessage: Statement on line 11: Type mismatch (usually a non-object value used where an object is required)Backtrace: Line 11 of inline#1 script in http://localhost/OOP/test.html window.watch("watched", (function (id,oldVal,newVal){ alert("You changed " + id + " from " + oldVal + " to " + newVal + "!");})); Line 44 of linked script http://localhost/JSConsole/JSApp.js.php main(); Line 55 of inline#1 script in http://localhost/JSConsole/JSConsole.html this.app.setup(); Line 23 of inline#1 script in http://localhost/JSConsole/JSConsole.html _this.setup(); At unknown location [statement source code not available]]
(Note: the backtrace is inaccurate because my original file calls main() in a round-about way.) I find nothing on Google about Opera not implementing this; do they have a reason for not doing so, is it a bug/non-standard-compliance, etc., or does anybody know?
Link to comment
Share on other sites

This works in Firefox, but I can't get it to work with Opera, Safari, or IE and I don't see an error message (Opera hasn't been cooperating with error messages lately, I still need to figure that out).

<html>	<head>		<script type="text/javascript">		testobj = new Object;		testobj.watched = 0;		alert("init");		testobj.watch (			'watched',			function(id, oldVal, newVal){				alert('You changed ' + id + ' from ' + oldVal + ' to ' + newVal + '!');			}		);		</script>	</head>	<body>	<script type="text/javascript">	alert("changing");	testobj.watched = 1;	</script>	</body></html>

I don't understand why this wouldn't work, object.watch was defined in Javascript 1.2. Dreamweaver might have been confused with the Actionscript version:http://livedocs.adobe.com/flashlite/2/main...e=00000738.html

Link to comment
Share on other sites

Doesn't the Object constructor need ()?EDIT: Never mind, although that does make me curious. Thanks for the info. :) (alert(testobj.watch) outputs undefined in Internet Explorer and Opera; I guess the function just doesn't have enough attention for the developers to realize/value its existence.)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...