Skip to content
Tone.js

Emitter

class ↳ extends Tone

Emitter gives classes which extend it the ability to listen for and emit events. Inspiration and reference from Jerome Etienne’s MicroEvent. MIT (c) 2011 Jerome Etienne.

read-only

name: string

The name of the class

Default: "Emitter"

dispose(): this

Clean up

Returns this

emit(event: EventType, ...args: any[]): this

Invoke all of the callbacks bound to the event with any arguments passed in.

Parameters

  • event EventType

    The name of the event.

  • args any[]

    The arguments to pass to the functions listening.

Returns this

off(event: EventType, callback?: (...args: any[]) => void): this

Remove the event listener.

Parameters

  • event EventType

    The event to stop listening to.

  • callback (…args: any[]) => void optional

    The callback which was bound to the event with Emitter.on. If no callback is given, all callbacks events are removed.

Returns this

on(event: EventType, callback: (...args: any[]) => void): this

Bind a callback to a specific event.

Parameters

  • event EventType

    The name of the event to listen for.

  • callback (…args: any[]) => void

    The callback to invoke when the event is emitted

Returns this

once(event: EventType, callback: (...args: any[]) => void): this

Bind a callback which is only invoked once

Parameters

  • event EventType

    The name of the event to listen for.

  • callback (…args: any[]) => void

    The callback to invoke when the event is emitted

Returns this

static

mixin(constr: any): void

Add Emitter functions (on/off/emit) to the object

Parameters

  • constr any