pigwin32 (1) [Avatar] Offline
I've been looking for more information about the EventRouter class and stumbled upon Barry's post. He modified the class as per
1. The constructor establishes a "routers" associative array on the DOM element and assigns an appropriate "this" to each one, exactly as you indicated. The code now looks like this:

jsEvent.EventRouter = function(el,eventType) {
this.lsnrs = new Array();
this.el = el;
if (!this.el.routers) {
this.el.routers = new Object();
el[eventType] = jsEvent.EventRouter.callback;
el.routers[eventType] = this;

2. The callback, which is invoked in the context of the DOM element and which knows what event type it is handling, uses the event type to resolve to the correct router object. Its code now looks like:

jsEvent.EventRouter.callback = function(event) {
var e = event||window.event;
var router = this.routers["on"+e.type];
This looks fairly reasonable to me but I noticed there was no follow-up from the authors to his last post. To me the issue with the original EventRouter is kind of glaring and should be addressed in the errata for the book. I guess my question is, do the authors of the book (which is excellent btw) actually use the EventRouter class and if so, is this an issue that they have struck. Do they use Barry's fix? Does the fix trigger the infamous IE memory leaks? Has anyone else had this problem?