11/**
2- * https://github.com/mrdoob/eventdispatcher.js/
2+ * This modules allows to dispatch event objects on custom JavaScript objects.
3+ *
4+ * Main repository: [eventdispatcher.js]{@link https://github.com/mrdoob/eventdispatcher.js/}
5+ *
6+ * Code Example:
7+ * ```js
8+ * class Car extends EventDispatcher {
9+ * start() {
10+ * this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
11+ * }
12+ *};
13+ *
14+ * // Using events with the custom object
15+ * const car = new Car();
16+ * car.addEventListener( 'start', function ( event ) {
17+ * alert( event.message );
18+ * } );
19+ *
20+ * car.start();
21+ * ```
322 */
4-
523class EventDispatcher {
624
25+ /**
26+ * Adds the given event listener to the given event type.
27+ *
28+ * @param {string } type - The type of event to listen to.
29+ * @param {Function } listener - The function that gets called when the event is fired.
30+ */
731 addEventListener ( type , listener ) {
832
933 if ( this . _listeners === undefined ) this . _listeners = { } ;
@@ -24,6 +48,13 @@ class EventDispatcher {
2448
2549 }
2650
51+ /**
52+ * Returns `true` if the given event listener has been added to the given event type.
53+ *
54+ * @param {string } type - The type of event.
55+ * @param {Function } listener - The listener to check.
56+ * @return {boolean } Whether the given event listener has been added to the given event type.
57+ */
2758 hasEventListener ( type , listener ) {
2859
2960 const listeners = this . _listeners ;
@@ -34,6 +65,12 @@ class EventDispatcher {
3465
3566 }
3667
68+ /**
69+ * Removes the given event listener from the given event type.
70+ *
71+ * @param {string } type - The type of event.
72+ * @param {Function } listener - The listener to remove.
73+ */
3774 removeEventListener ( type , listener ) {
3875
3976 const listeners = this . _listeners ;
@@ -56,6 +93,11 @@ class EventDispatcher {
5693
5794 }
5895
96+ /**
97+ * Dispatches an event object.
98+ *
99+ * @param {Object } event - The event that gets fired.
100+ */
59101 dispatchEvent ( event ) {
60102
61103 const listeners = this . _listeners ;
0 commit comments