|
Sydney | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object | +--EventTable
Defined in event_table.js
Constructor Summary | |
EventTable
(<Array> eventList)
Creates an event table that can map event names to functions to be called when those events are raised. |
Method Summary | |
boolean
|
addEventListener(<string> event, <Function> listener)
Registers a listener for the named event. |
void
|
addEventType(<string> event)
Adds the named event to the list of events in this table. |
boolean
|
hasEvent(<string> event)
Returns true if this event table has an
event named event .
|
void
|
raiseEvent(<string> eventName, <Object> eventObj)
Raises the event named eventName and passes eventObj
to all registered listeners.
|
boolean
|
removeEventListener(<string> event, <Function> listener)
Deregisters a listener from the named event. |
string
|
toString()
Returns a string representation of this event table for debugging purposes. |
Constructor Detail |
function EventTable(<Array> eventList)
eventList
- a list of strings, each of which is the name of an event that this table should govern
Method Detail |
boolean addEventListener(<string> event, <Function> listener)
listener
has already been registered for the event named event
. Note
that this condition is checked with the equality operator, so two functions
that do the same thing but are different instances of the Function
class can both be registered for the same event, and both will be called
when the event is raised.
For example, the following code will generate 5 alert boxes:
var eventTable = new EventTable(['alert']); for(var i = 0; i < 5; ++i) { eventTable.addEventListener('alert', function() { alert('The event named "alert" was raised'); }); } eventTable.raiseEvent('alert', null);whereas the following code will only generate one alert box:
var eventTable = new EventTable(['alert']); function showAlert() { alert('The event named "alert" was raised'); } for(var i = 0; i < 5; ++i) { eventTable.addEventListener('alert', showAlert); } eventTable.raiseEvent('alert', null);
event
- the name of the event to which listener
should be attached
listener
- a function to be called whenever the event named event
is raised. There is no guarantee about the order in which listeners are called for a given event. listener
can be passed one argument. This argument depends on the semantics of the event and is passed indirectly by the event raiser.
true
if listener
was added and false
if not. A listener will not be added a second time to the same event.
void addEventType(<string> event)
event
- the name of the event to add
boolean hasEvent(<string> event)
true
if this event table has an
event named event
.
event
- the name of the event to check for
true
if this event table has an event named event
and false
if not
void raiseEvent(<string> eventName, <Object> eventObj)
eventName
and passes eventObj
to all registered listeners. Note that if any of the listeners cause this
instance of EventTable
to raise the same event as is currently
being raised (directly or indirectly), the secondary attempts will be
ignored—this is to avoid infinite loops like the following (ie. the
following example will terminate because EventTable
blocks the raiseEvent
call that is made inside the listener):
var eventTable = new EventTable(['infinite']); // register a listener that raises the event currently being raised eventTable.addEventListener('infinite', function() { eventTable.raiseEvent('infinite', null); }); // initiate the infinite loop eventTable.raiseEvent('infinite', null);
eventName
- the name of the event to raise. This event table must have an event by this name or an exception will be thrown.
eventObj
- (Optional) - an argument to pass to all listeners registered for this event. EventTable
imposes no meaning or restrictions on eventObj
.
boolean removeEventListener(<string> event, <Function> listener)
listener
wasn't registered for event
in
the first place.
event
- the name of the event from which listener
should be deregistered
listener
- the function that should no longer be called when the event named event
is raised
true
if listener
was deregistered and false
if not.
string toString()
|
Sydney | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |