Last active
January 14, 2022 09:42
-
-
Save holgergp/07e7680832f6f77b66b34d5020c3db6c to your computer and use it in GitHub Desktop.
Private Field Presence Checks (TypeScript 4.5 Article)
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 Person { | |
#name: string; | |
constructor(name: string) { | |
this.#name = name; | |
} | |
equals(other: unknown) { | |
return other && | |
typeof other === "object" && | |
#name in other && // <- this is new! | |
this.#name === other.#name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment