EventDispatcher.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>EventDispatcher - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">EventDispatcher</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>This modules allows to dispatch event objects on custom JavaScript objects.</p>
  16. <p>Main repository: <a href="https://github.com/mrdoob/eventdispatcher.js/">eventdispatcher.js</a></p>
  17. <p>Code Example:</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">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></pre></div>
  31. </header>
  32. <article>
  33. <div class="container-overview">
  34. <h2>Constructor</h2>
  35. <h3 class="name name-method" id="EventDispatcher" translate="no">new <a href="#EventDispatcher">EventDispatcher</a><span class="signature">()</span> </h3>
  36. <div class="method">
  37. </div>
  38. </div>
  39. <h2 class="subsection-title">Methods</h2>
  40. <h3 class="name name-method" id="addEventListener" translate="no">.<a href="#addEventListener">addEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span> </h3>
  41. <div class="method">
  42. <div class="description">
  43. <p>Adds the given event listener to the given event type.</p>
  44. </div>
  45. <table class="params">
  46. <tbody>
  47. <tr>
  48. <td class="name"><code>type</code></td>
  49. <td class="description last"><p>The type of event to listen to.</p></td>
  50. </tr>
  51. <tr>
  52. <td class="name"><code>listener</code></td>
  53. <td class="description last"><p>The function that gets called when the event is fired.</p></td>
  54. </tr>
  55. </tbody>
  56. </table>
  57. </div>
  58. <h3 class="name name-method" id="dispatchEvent" translate="no">.<a href="#dispatchEvent">dispatchEvent</a><span class="signature">( event : <span class="param-type">Object</span> )</span> </h3>
  59. <div class="method">
  60. <div class="description">
  61. <p>Dispatches an event object.</p>
  62. </div>
  63. <table class="params">
  64. <tbody>
  65. <tr>
  66. <td class="name"><code>event</code></td>
  67. <td class="description last"><p>The event that gets fired.</p></td>
  68. </tr>
  69. </tbody>
  70. </table>
  71. </div>
  72. <h3 class="name name-method" id="hasEventListener" translate="no">.<a href="#hasEventListener">hasEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span><span class="type-signature"> : boolean</span> </h3>
  73. <div class="method">
  74. <div class="description">
  75. <p>Returns <code>true</code> if the given event listener has been added to the given event type.</p>
  76. </div>
  77. <table class="params">
  78. <tbody>
  79. <tr>
  80. <td class="name"><code>type</code></td>
  81. <td class="description last"><p>The type of event.</p></td>
  82. </tr>
  83. <tr>
  84. <td class="name"><code>listener</code></td>
  85. <td class="description last"><p>The listener to check.</p></td>
  86. </tr>
  87. </tbody>
  88. </table>
  89. <dl class="details">
  90. <dt class="tag-returns"><strong>Returns:</strong> Whether the given event listener has been added to the given event type.</dt>
  91. </dl>
  92. </div>
  93. <h3 class="name name-method" id="removeEventListener" translate="no">.<a href="#removeEventListener">removeEventListener</a><span class="signature">( type : <span class="param-type">string</span>, listener : <span class="param-type">function</span> )</span> </h3>
  94. <div class="method">
  95. <div class="description">
  96. <p>Removes the given event listener from the given event type.</p>
  97. </div>
  98. <table class="params">
  99. <tbody>
  100. <tr>
  101. <td class="name"><code>type</code></td>
  102. <td class="description last"><p>The type of event.</p></td>
  103. </tr>
  104. <tr>
  105. <td class="name"><code>listener</code></td>
  106. <td class="description last"><p>The listener to remove.</p></td>
  107. </tr>
  108. </tbody>
  109. </table>
  110. </div>
  111. <h2 class="subsection-title">Source</h2>
  112. <p>
  113. <a href="https://github.com/mrdoob/three.js/blob/master/src/core/EventDispatcher.js" target="_blank" rel="noopener" translate="no">src/core/EventDispatcher.js</a>
  114. </p>
  115. </article>
  116. </section>
  117. <script src="../scripts/linenumber.js"></script>
  118. <script src="../scripts/page.js"></script>
  119. </body>
  120. </html>
粤ICP备19079148号