Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IEventTarget

Interface for all classes that self implement the EventTarget protocol, they are normally not sub class of EventTarget

Hierarchy

Implemented by

Index

Properties

_callbackTable

_callbackTable: ICallbackTable = createMap(true)

Methods

emit

  • emit(key: string, ...args: any[]): void
  • Trigger an event directly with the event name and necessary arguments.

    Parameters

    • key: string

      event type

    • Rest ...args: any[]

      Arguments when the event triggered

    Returns void

hasEventListener

  • hasEventListener(key: string, callback?: Function, target?: Object | null): boolean
  • Checks whether there is correspond event listener registered on the given event

    Parameters

    • key: string

      Event type

    • Optional callback: Function

      Callback function when event triggered

    • Default value target: Object | null = null

      Callback callee

    Returns boolean

off

  • off(type: string, callback?: Function, target?: Object): void
  • Removes the listeners previously registered with the same type, callback, target and or useCapture, if only type is passed as parameter, all listeners registered with that type will be removed.

    example

    // register fire eventListener var callback = eventTarget.on('fire', function () { cc.log("fire in the hole"); }, target); // remove fire event listener eventTarget.off('fire', callback, target); // remove all fire event listeners eventTarget.off('fire');

    Parameters

    • type: string

      A string representing the event type being removed.

    • Optional callback: Function

      The callback to remove.

    • Optional target: Object

      The target (this object) to invoke the callback, if it's not given, only callback without target will be removed

    Returns void

on

  • on(type: string, callback: Function, target?: Object): undefined | Function
  • Register an callback of a specific event type on the EventTarget. This type of event should be triggered via emit.

    example

    eventTarget.on('fire', function () { cc.log("fire in the hole"); }, node);

    Parameters

    • type: string

      A string representing the event type to listen for.

    • callback: Function

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional target: Object

      The target (this object) to invoke the callback, can be null

    Returns undefined | Function

    • Just returns the incoming callback so you can save the anonymous function easier.

once

  • once(type: string, callback: Function, target?: Object): undefined | Function
  • Register an callback of a specific event type on the EventTarget, the callback will remove itself after the first time it is triggered.

    example

    eventTarget.once('fire', function () { cc.log("this is the callback and will be invoked only once"); }, node);

    Parameters

    • type: string

      A string representing the event type to listen for.

    • callback: Function

      The callback that will be invoked when the event is dispatched. The callback is ignored if it is a duplicate (the callbacks are unique).

    • Optional target: Object

      The target (this object) to invoke the callback, can be null

    Returns undefined | Function

removeAll

  • removeAll(keyOrTarget?: string | Object): void
  • Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

    Parameters

    • Optional keyOrTarget: string | Object

      The event type or target with which the listeners will be removed

    Returns void

targetOff

  • targetOff(keyOrTarget?: string | Object): void
  • Removes all callbacks previously registered with the same target (passed as parameter). This is not for removing all listeners in the current event target, and this is not for removing all listeners the target parameter have registered. It's only for removing all listeners (callback and target couple) registered on the current event target by the target parameter.

    Parameters

    • Optional keyOrTarget: string | Object

    Returns void

Generated using TypeDoc