Skip to content Skip to sidebar Skip to footer

Custom Javascript Eventmanager - Please Help Me Complete

I am trying to create a custom javascript EventManager class. I've adopted the format Grant Skinner uses in his easel.js framework for creating the class and need to stick with it.

Solution 1:

Here's a working example of fixed code: http://jsfiddle.net/JxYca/3/

For the most part your code was working, just a few small problems here and there. IFFE is Immediately-Invoked Function Expression (IIFE). This is what you were doing with the whole function(window) {}(window). However in this case it's absolutely unnecessary and just pollutes the code. There's no such thing as hashtable in javascript, however, you can just use an object instead of it. The names of the properties become a key and their value is now value of the hashtable.

An additional and sort of unrelated though for you. This way of doing events in nice, but if you have, say, 3 handlers attached to an event, and second one fails with JavaScript exception, third one will never get executed. You might want to take a quick look at how prototype.js does events here: https://github.com/sstephenson/prototype/blob/master/src/prototype/dom/event.js Their events are non-blocking.

Post a Comment for "Custom Javascript Eventmanager - Please Help Me Complete"