Building an observer widget
The typical approach to dealing with events triggered by jQuery UI widgets is to bind an event handler to that event name, passed directly into the constructor. It's the typical approach because it's easy to do, and it generally solves a specific problem we're having. For example, suppose that when a section of our accordion widget is expanded, we would like to update another DOM element. To do this, assign an event handler function to the activate event when the accordion is constructed.
This approach works well for small, single purpose jobs that apply to a single instance of a given widget. However, most meaningful applications have many widgets, all triggering their own events. The widget factory prefixes each event with the name of the widget, which generally means that even outside of the widget context we know what we're working with. This is especially helpful when we want to bind event handlers to widget events, long after the widget has been created.
Let...