I need help understanding this part of the code. What is the point handler.guid? Why is there a need for a hash table?
What's the point:
if ( element["on" + type])
{
handlers[0] = element["on" + type];
}
What does "this" mean in handleEventan addEvent element or function?
function addEvent(element, type, handler)
{
if (!handler.$$guid) handler.$$guid = addEvent.guid++;
if (!element.events) element.events = {};
var handlers = element.events[type];
if (!handlers)
{
handlers = element.events[type] = {};
if (element["on" + type])
{
handlers[0] = element["on" + type];
}
}
handlers[handler.$$guid] = handler;
element["on" + type] = handleEvent;
}
addEvent.guid = 1;
function removeEvent(element, type, handler)
{
if (element.events && element.events[type])
{
delete element.events[type][handler.$$guid];
}
}
function handleEvent(event)
{
event = event || window.event;
var handlers = this.events[event.type];
for (var i in handlers)
{
this.$$handleEvent = handlers[i];
this.$$handleEvent(event);
}
}
steve source
share