EventDispatcher.html 1.9 KB

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