- an event object has
subscribe
andunsubscribe
methods to add and remove handlers subscribe
andunsubscribe
are able to take an arbitrary number of arguments and tolerate invalid arguments (not functions, or for unsubscribe, functions which are not subscribed) by skipping them- multiple subscription of the same handler is allowed, and in this case unsubscription removes the last subscription of the same handler
- an event object has an
emit
method which must invoke all the handlers with the arguments provided emit
uses its own invocation context as handers' invocation context- the order of handlers invocation matches the order of subscription
- handler functions can subscribe and unsubscribe handlers, but the changes apply to the next emit call - the handlers for an ongoing emit call are not affected
subscribe
,unsubscribe
andemit
are the only public properties of event objects (apart from Object.prototype methods)
A script by V.