Created
October 31, 2013 12:14
-
-
Save thebuilder/7248688 to your computer and use it in GitHub Desktop.
Events with correct scope in TypeScript
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 Tracker { | |
count = 0; | |
constructor() { | |
window.addEventListener("mousedown", this.mouseDown); | |
window.addEventListener("mouseup", this.mouseUp); | |
} | |
mouseDown = (ev: MouseEvent) => { | |
window.addEventListener("mousemove", this.mouseMove); | |
} | |
mouseUp = (ev: MouseEvent) => { | |
window.removeEventListener("mousemove", this.mouseMove); | |
} | |
mouseMove = (ev: MouseEvent) => { | |
this.count++; | |
console.log(this.count); | |
} | |
} | |
new Tracker(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment