Thread:Kangaroopower/@comment-3508190-20120617231339

To answer your question about what I like about even-driven Javascript: The loose coupling. Since my Shadow object is event-driven, I can easily attach it to any interface I like. It will just sit there and wait and magically spring to live when an event comes - regardless of who or what triggers the event. When it has done its job it will trigger events to propagate the results. Who are what - if anything at all - listens to the events is irrelevant. It is completely independent. It doesn't share any properties. It doesn't need to call any other module's methods and it doesn't expose any itself.

Strictly speaking I'm not using events at all btw. I use a pub/sub system:

Objects subscribe to "topics" in this system like so:

$('#button').subscribe('editorReady', function  {     // do stuff... });

And another object can publish that topic with:

$.publish('editorReady');

which will call all functions that were registered to that topic.

The subscribers do not know anything about the publishers and vice versa. Any object can subscribe to as many topics as it wants and publish as many as it wants at any time. It hardly gets much looser than that. 