If I'm using one handler to listen to several events, it would be super useful if I could switch based on the namespaced event type. For example:
var foo = $('.foo');
foo.bind('custom',function(event) {
switch (event.namespace) {
case 'custom.show':
// stuff to do on show
beak;
case 'custom.hide':
// stuff to do on show
beak;
}
});
foo.trigger('custom.show');
foo.trigger('custom.hide');
I know I can pass in data when triggering the event, but this seems a bloaty way to do things when the events system already knows internally what the namespaced event type is.
Exposing this on the event object is extremely trivial. In the handler() method in the current public release of jQuery 1.2.3 just store the original type, before splitting in to it's parts, before line 2059:
event.namespace = event.type;
Voila! Super simple and does away with the need for messy data objects. This would make it trivial to listen to all events from a UI control, for example, with a single method that just switches based on the event namespace.