EventDispatcher.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="../../list.js"></script>
  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. <div class="desc">JavaScript events for custom objects.</div>
  12. <h2>Example</h2>
  13. <code>
  14. var Car = function () {
  15. EventDispatcher.call( this );
  16. this.start = function () {
  17. this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
  18. };
  19. };
  20. var car = new Car();
  21. car.addEventListener( 'start', function ( event ) {
  22. alert( event.message );
  23. } );
  24. car.start();
  25. </code>
  26. <h2>Constructor</h2>
  27. <h3>[name]()</h3>
  28. <div>
  29. Creates eventDispatcher object. It needs to be called with '.call' to add its functionality to an object.
  30. </div>
  31. <h2>Methods</h2>
  32. <h3>.addEventListener( [page:String type], [page:Function listener] )</h3>
  33. <div>
  34. type - The type of event to listen to.<br />
  35. listener - The function that gets called when the event is fired.
  36. </div>
  37. <div>
  38. Adds a listener to an event type.
  39. </div>
  40. <h3>.removeEventListener( [page:String type], [page:Function listener] )</h3>
  41. <div>
  42. type - The type of the listener that gets removed.<br />
  43. listener - The listener function that gets removed.
  44. </div>
  45. <div>
  46. Removes a listener from an event type.
  47. </div>
  48. <h3>.dispatchEvent( [page:String type] )</h3>
  49. <div>
  50. type - The type of event that gets fired.
  51. </div>
  52. <div>
  53. Fire an event type.
  54. </div>
  55. <h2>Source</h2>
  56. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  57. </body>
  58. </html>