Internet Explorer 5.0 Preview, Part I: Passing Objects to Behaviors - Doc JavaScript | WebReference

Internet Explorer 5.0 Preview, Part I: Passing Objects to Behaviors - Doc JavaScript


Passing Objects to Behaviors

A Behavior operates on an object that is associated with a DHTML element. In our Blinking Soccer example, we first define a Behavior named soccer in the scriptlet file, and then, by assigning it to the CLASS attribute, we associate a DIV element with this Behavior:


<DIV CLASS="soccer" ...

Once a Behavior is associated with a DHTML element, any operation inside the Behavior definition script is assumed to operate on the DHTML element's object. When you manipulate properties inside the soccer Behavior, for example, you actually manipulate the properties of the relevant DHTML object. The following lines from the soccer scriptlet change the visibility and position of the DIV object in the Web page:


style.position = "absolute";
style.pixelTop = x;
style.pixelLeft = y;

Referencing an object's methods is more complicated. Internet Explorer 5.0 does not default to the relevant DHTML object. Instead, it provides you with the uniqueID mechanism. The uniqueID is a unique ID of the DHTML object that is currently being operated by the Behavior. When we want to use the blink() method in our Blinking Soccer example, we call it as uniqueID+".blink()". When we want to schedule the blinking msecs milliseconds in the future, we use:


window.setTimeout(uniqueID+".blink()", msecs);

https://www.internet.com


Created: July 19, 1998
Revised: July 19, 1998

URL: https://www.webreference.com/js/column22/objects.html