onEvent
Register a named event handler on an observable object
onEvent(obj, eventName, callback)
Register an event handler on the object obj
to trigger when the event eventName
is dispatched.
obj
must implement @@can.onEvent or .addEventListener()
to be compatible
with can-reflect.onKeyValue. The function passed as callback
will receive the event descriptor as the first
argument, and any data passed to the event dispatch as subsequent arguments.
var obj = new DefineMap({ foo: "bar" });
canReflect.onEvent(obj, "foo", function(ev, newVal, oldVal) {
console.log("foo is now", newVal, ", was", oldVal);
});
canEvent.dispatch.call(obj, "foo", ["baz", "quux"]); // -> logs "foo is now baz , was quux"
Parameters
- obj
{Object}
:the object to bind a new event handler to
- eventName
{String}
:the name of the event to bind the handler to
- callback
{function(*)}
:the handler function to bind to the event