Events/D
From CommonJS Spec Wiki
< Events
STATUS: PROPOSAL
This proposal is a strict subset of the DOM2 events API [1].
Contents
Proposal
- createEvent(type String) Undefined
- constructs and returns a new Event with the given type
EventTarget
- addEventListener(type String, listener Function)
- pushes an event listener onto the internal array of listener functions for the given event type.
- removeEventListener(type String, listener Function)
- removes the given listener function from the internal array of listener functions for the given type.
- dispatchEvent(event Event) Boolean throws EventException
- sets the event's target to this object and calls each listener function in order with the given event as an argument until the event's stopPropagation method is called.
Event
No constructor; use createEvent
.
- initEvent()
- initializes the event. Must be called before dispatching.
- type String
- the type name of the event, as set by
createEvent
- target EventTarget
- the target of the event, as set by
dispatchEvent
- stopPropagation() Undefined
- prevents an event from being propagated to further listeners.
- preventDefault() Undefined
- this specification does not provide a mechanism for defining default actions for event types, so this is a no-op unless implementations of dispatchEvent for particular objects opt to define the behavior for particular event types on particular targets.
EventException
- code Number
- implementation defined.
Examples
Removing a Listener
var listener = function (event) {}; var target = new EventTarget(); target.addEventListener("foo", listener); target.removeEventListener("foo", listener);
Listening Before Another Listener
Not supported.
Listening After another Listener
var target = new EventTarget(); target.addEventListener("foo", function (event) {print("before")}); target.addEventListener("foo", function (event) {print("after")}); var event = createEvent(); event.initEvent(); target.dispatch(event)
before after
Emit Arguments
Not supported.