topical media & game development

talk show tell print

mobile-query-three-plugins-cannonjs-vendor-cannon.js-src-utils-EventTarget.js / js



  /*global CANNON:true */
  
  
@class CANNON.EventTarget
see: github.com/mrdoob/eventtarget.js/

  
  CANNON.EventTarget = function () {
      var listeners = {};
      this.addEventListener = function ( type, listener ) {
          if ( listeners[ type ] == undefined ) {
              listeners[ type ] = [];
          }
          if ( listeners[ type ].indexOf( listener ) === - 1 ) {
              listeners[ type ].push( listener );
          }
      };
      this.dispatchEvent = function ( event ) {
          for ( var listener in listeners[ event.type ] ) {
              listeners[ event.type ][ listener ]( event );
          }
      };
      this.removeEventListener = function ( type, listener ) {
          var index = listeners[ type ].indexOf( listener );
          if ( index !== - 1 ) {
              listeners[ type ].splice( index, 1 );
          }
      };
  };


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.