2
0

EventDispatcher.html 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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>
  33. Creates EventDispatcher object.
  34. </p>
  35. <h2>Methods</h2>
  36. <h3>[method:null addEventListener]( [param:String type], [param:Function listener] )</h3>
  37. <p>
  38. type - The type of event to listen to.<br />
  39. listener - The function that gets called when the event is fired.
  40. </p>
  41. <p>
  42. Adds a listener to an event type.
  43. </p>
  44. <h3>[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )</h3>
  45. <p>
  46. type - The type of event to listen to.<br />
  47. listener - The function that gets called when the event is fired.
  48. </p>
  49. <p>
  50. Checks if listener is added to an event type.
  51. </p>
  52. <h3>[method:null removeEventListener]( [param:String type], [param:Function listener] )</h3>
  53. <p>
  54. type - The type of the listener that gets removed.<br />
  55. listener - The listener function that gets removed.
  56. </p>
  57. <p>
  58. Removes a listener from an event type.
  59. </p>
  60. <h3>[method:null dispatchEvent]( [param:Object event] )</h3>
  61. <p>
  62. event - The event that gets fired.
  63. </p>
  64. <p>
  65. Fire an event type.
  66. </p>
  67. <h2>Source</h2>
  68. <p>
  69. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  70. </p>
  71. </body>
  72. </html>