JavaScript events for custom objects

// Adding events to a custom object
class Car extends EventDispatcher {
start() {
this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
}
};
// Using events with the custom object
const car = new Car();
car.addEventListener( 'start', ( event ) => {
alert( event.message );
} );
car.start();

Type Parameters

Hierarchy (view full)

Constructors

Properties

depth: number
depthBuffer: boolean
true
depthTexture: DepthTexture
null
height: number
isRenderTarget
samples: number

Defines the count of MSAA samples. Can only be used with WebGL 2. Default is 0.

0
scissor: Vector4
scissorTest: boolean
false
stencilBuffer: boolean
true
texture: TTexture
viewport: Vector4
width: number

Methods

  • Adds a listener to an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void

  • Returns this

  • Parameters

    Returns this

  • Fire an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    • event: BaseEvent<T> & {
          dispose: {};
      }[T]

      The event that gets fired.

    Returns void

  • Returns void

  • Checks if listener is added to an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    Returns boolean

  • Type Parameters

    • T extends string

    Parameters

    Returns boolean

  • Removes a listener from an event type.

    Type Parameters

    • T extends "dispose"

    Parameters

    Returns void

  • Type Parameters

    • T extends string

    Parameters

    Returns void

  • Parameters

    • width: number
    • height: number
    • Optionaldepth: number

    Returns void