One of the nice things about MooTools, is that it lets you easily assign/fire events to objects, for example:
var playerSingleton = new (new Class({
Implements: [Events],
initialize: function() {},
setVolume: function() {
// do some stuff..
this.fireEvent('volumeChanged')
}
}));
// Somewhere else...
playerSingleton.addEvent('volumeChanged', function() {
// do something when volume changes
});
playerSingleton.setVolume(75);
// bam our event fires.
How would something like this be done with jQuery?
I know there's .bind
and .trigger
, but it seems like the only way to do this is to bind/fire events to the window object:
$(window).bind('volumeChanged', fn);
Is there anything better than this, more like the MooTools approach? Thanks!