Menu Home

dispatchEvent(): Synchronous?

Apparently, yes!

So I’m experimenting with using custom events to transfer data between dependencies of a object and the object itself. Simple right?

And it really is. I just assumed that the event sent would be asynchronous – you know, like when a ‘click’ event is sent, the event handler consumes it while JavaScript goes on its merry way.

But that’s not the case with dispatchEvent().

Any event handlers listening to an event sent by dispatchEvent() are executed first, then the code following dispatchEvent() is done.

Who’d thunk it? Well, probably just about everybody but myself.

You can read all about it in the MDN docs.

Categories: HTML Javascript

Tagged as:

thevirtuoid

Web Tinkerer. No, not like Tinkerbell.

Creator of the game Virtuoid. Boring JavaScript. Visit us at thevirtuoid.com

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: