addbehaviour
addBehavior is psuedo Asynchronous
Microsoft's documentation for the addBehavior method almost implies that the method is added to elements asynchronously. It says:
Unless the behavior specified in the addBehavior call is one of the default behaviors built into Internet Explorer, the addBehavior call causes Internet Explorer to download the behavior asynchronously, before the behavior is attached to the element.
This sentence is a little ambiguous; it could mean that the behaviour is only downloaded asynchronously and then applied to the element synchronously, or that the entire method is asynchronous, downloading and all. The next paragraph in the documentation starts Due to the asynchronous nature of the
, although all that can be deduced from this is that the method is not blocking, which is quite true.
addBehavior method, its return value cannot be relied on [...]
If we require any of the methods the behaviour implements then it would be very useful if the addBehavior method was blocking, or if we could make it blocking. If it was actually asynchronous we could simply wait until the methods we want to use are added, probably by sitting in a while loop. Unfortuantly this doesn't seem to work, Internet Explorer will just sit in a loop forever more.
I'm not sure what this implies about the synchronous nature of the addBehavior method, but any methods added using behaviours are not exposed during the same execution path the addBehavior call was made, so as far as I am concerned this method is only pseudo asynchronous.
If you need to wait for a behaviour to be added then one way is to listen for the oncontentready event using the PUBLIC:ATTACH element in your HTML Component file; when this is called your behaviours should be there and exposed.

0 Comments:
Post a Comment
<< Home