Same as this question, but Prototype library specific:
I’ve got a Browser class, and I want to fire and observe custom events for this class. Prototype’s custom event system only lets me bind to and fire events on DOM elements. Here’s my first idea as to an alternative:
function Browser() {
this.event = new Element('span');
}
Browser.prototype.render = function() {
this.event.fire('browser:render');
}
var browser = new Browser();
browser.event.observe('browser:render', function() { ... });
Is there a better way to do this?
Thanks in part to Frits van Campen’s advice, I made my own that serves my needs, a little more sophisticated than Frits’ sample.
Then I can do: