EventDispatcher.html 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <p class="desc">
  13. JavaScript events for custom objects.<br />
  14. [link:https://github.com/mrdoob/eventdispatcher.js Eventdispatcher on GitHub]
  15. </p>
  16. <h2>Code Example</h2>
  17. <code>
  18. // Adding events to a custom object
  19. class Car extends EventDispatcher {
  20. start() {
  21. this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
  22. }
  23. };
  24. // Using events with the custom object
  25. const car = new Car();
  26. car.addEventListener( 'start', function ( event ) {
  27. alert( event.message );
  28. } );
  29. car.start();
  30. </code>
  31. <h2>Constructor</h2>
  32. <h3>[name]()</h3>
  33. <p>
  34. Creates EventDispatcher object.
  35. </p>
  36. <h2>Methods</h2>
  37. <h3>[method:null addEventListener]( [param:String type], [param:Function listener] )</h3>
  38. <p>
  39. type - The type of event to listen to.<br />
  40. listener - The function that gets called when the event is fired.
  41. </p>
  42. <p>
  43. Adds a listener to an event type.
  44. </p>
  45. <h3>[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )</h3>
  46. <p>
  47. type - The type of event to listen to.<br />
  48. listener - The function that gets called when the event is fired.
  49. </p>
  50. <p>
  51. Checks if listener is added to an event type.
  52. </p>
  53. <h3>[method:null removeEventListener]( [param:String type], [param:Function listener] )</h3>
  54. <p>
  55. type - The type of the listener that gets removed.<br />
  56. listener - The listener function that gets removed.
  57. </p>
  58. <p>
  59. Removes a listener from an event type.
  60. </p>
  61. <h3>[method:null dispatchEvent]( [param:object event] )</h3>
  62. <p>
  63. event - The event that gets fired.
  64. </p>
  65. <p>
  66. Fire an event type.
  67. </p>
  68. <h2>Source</h2>
  69. <p>
  70. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  71. </p>
  72. </body>
  73. </html>