Created
January 31, 2017 14:05
-
-
Save samverneck/f8e2491dfcd8ea8f5cc7a0432b36321b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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