EventTarget.js 708 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * https://github.com/mrdoob/eventtarget.js/
  3. */
  4. THREE.EventTarget = function () {
  5. var listeners = {};
  6. this.addEventListener = function ( type, listener ) {
  7. if ( listeners[ type ] === undefined ) {
  8. listeners[ type ] = [];
  9. }
  10. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  11. listeners[ type ].push( listener );
  12. }
  13. };
  14. this.dispatchEvent = function ( event ) {
  15. for ( var i = 0; i < listeners[ event.type ].length; i ++ ) {
  16. listeners[ event.type ][ i ]( event );
  17. }
  18. };
  19. this.removeEventListener = function ( type, listener ) {
  20. var index = listeners[ type ].indexOf( listener );
  21. if ( index !== - 1 ) {
  22. listeners[ type ].splice( index, 1 );
  23. }
  24. };
  25. };
粤ICP备19079148号