Last active
April 17, 2020 22:04
-
-
Save EdCharbeneau/c4af5cbbf0dad1e350c8ba285b6239b7 to your computer and use it in GitHub Desktop.
TypeWtf
This file contains 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
export MyClass { | |
private foo: string = "hello"; | |
public addHandler() { | |
window.addEventListener("resize", this.logResize); | |
} | |
public logResize() { | |
console.log(this); // Expected: MyClass | Actual: Window | |
console.log(foo); // Expected: "hello" | Actual: Undefined | |
} | |
//fixed | |
public logResize = () => { | |
console.log(this); // Expected: MyClass | Actual: Window | |
console.log(foo); // Expected: "hello" | Actual: Undefined | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment