Skip to content

Instantly share code, notes, and snippets.

@cia48621793
Created July 11, 2016 08:19
Show Gist options
  • Save cia48621793/86c43b330c32ec03b0a6a36dd92006ad to your computer and use it in GitHub Desktop.
Save cia48621793/86c43b330c32ec03b0a6a36dd92006ad to your computer and use it in GitHub Desktop.
class EventListener<T> {
private callbacks:{(user : T) : void}[] = [];
addEventListener(callback:{(user : T) : void}):void {
this.callbacks.push(callback);
}
removeEventListener(callback:{(user: T) : void}):void {
this.callbacks.splice(this.callbacks.lastIndexOf(callback));
}
fireEventListener(user:T) {
this.callbacks.forEach(_ => _(user));
}
}
var event = new EventListener<number>();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment