EventDispatcher.html 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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>Example</h2>
  17. <code>
  18. // Adding events to a custom object
  19. var Car = function () {
  20. this.start = function () {
  21. this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
  22. };
  23. };
  24. // Mixing the EventDispatcher.prototype with the custom object prototype
  25. Object.assign( Car.prototype, EventDispatcher.prototype );
  26. // Using events with the custom object
  27. var car = new Car();
  28. car.addEventListener( 'start', function ( event ) {
  29. alert( event.message );
  30. } );
  31. car.start();
  32. </code>
  33. <h2>Constructor</h2>
  34. <h3>[name]()</h3>
  35. <p>
  36. Creates EventDispatcher object.
  37. </p>
  38. <h2>Methods</h2>
  39. <h3>[method:null addEventListener]( [param:String type], [param:Function listener] )</h3>
  40. <p>
  41. type - The type of event to listen to.<br />
  42. listener - The function that gets called when the event is fired.
  43. </p>
  44. <p>
  45. Adds a listener to an event type.
  46. </p>
  47. <h3>[method:Boolean hasEventListener]( [param:String type], [param:Function listener] )</h3>
  48. <p>
  49. type - The type of event to listen to.<br />
  50. listener - The function that gets called when the event is fired.
  51. </p>
  52. <p>
  53. Checks if listener is added to an event type.
  54. </p>
  55. <h3>[method:null removeEventListener]( [param:String type], [param:Function listener] )</h3>
  56. <p>
  57. type - The type of the listener that gets removed.<br />
  58. listener - The listener function that gets removed.
  59. </p>
  60. <p>
  61. Removes a listener from an event type.
  62. </p>
  63. <h3>[method:null dispatchEvent]( [param:object event] )</h3>
  64. <p>
  65. event - The event that gets fired.
  66. </p>
  67. <p>
  68. Fire an event type.
  69. </p>
  70. <h2>Source</h2>
  71. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  72. </body>
  73. </html>