An event handler which is passed to the method add()
can take one of the following formats.
The function that is called directly.
emitter.add("event", function (e) {
console.log("I am event handler");
});
The function takes a single argument Event object.
The this
inside the function is NULL.
The numeric list with 2 or 3 elements:
{Object}
- thisArg{Function|string}
- a method or a method name{any[]}
- bound arguments
Examples:
[object, method]
ismethod.call(object, event)
[object, "method"]
isobject.method(event)
[object, "method", [1, 2, 3]]
isobject.method(1, 2, 3, event)
Method by name computed each time.
var obj = {
method: function () {
console.log("one");
}
};
emitter.add([obj, "method"]);
emitter.emit(e); // "one"
obj.method = function () {
console.log("two");
};
emitter.emit(e); // "two"
If a handler returns FALSE
it is the same as e.preventDefault()
and e.stopPropagation()
.
See Event object.