This is very similar to this question.
My question is more about sample code.
the code:
var eventuality = function (that) {
var registry = {};
that.fire = function (event) {
var array,
func,
handler,
i,
type = typeof event === 'string' ?
event : event.type;
if (registry.hasOwnProperty(type)) {
array = registry[type];
for (i = 0; i < array.length; i += 1) {
handler = array[i];
func = handler.method;
if (typeof func === 'string') {
func = this[func];
}
func.apply(this,
handler.parameters || [event]);
}
}
return this;
};
that.on = function (type, method, parameters) {
var handler = {
method: method,
parameters: parameters
};
if (registry.hasOwnProperty(type)) {
registry[type].push(handler);
} else {
registry[type] = [handler];
}
return this;
};
return that;
}
in the code, I do not understand this line func = handler.method;.
How it works? I mean handler.method should be undefined, right?
thank
source
share