Last active
October 29, 2023 12:24
-
-
Save ronshapiro/c8bb0a34517fbb90f6dddc8972677d65 to your computer and use it in GitHub Desktop.
Typescript rewriting constructor properties
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
class F { | |
constructor(protected a: string) { | |
console.log("F.a", a); | |
console.log("F.this.a", this.a); | |
} | |
b() { | |
console.log("F.b.this.a", this.a); | |
} | |
} | |
class F2 extends F { | |
constructor(protected a: string) { | |
super("start|" + a + "|end"); | |
console.log("F2.a", a); | |
console.log("F2.this.a", this.a); | |
} | |
} | |
new F("*").b(); | |
console.log(""); | |
new F2("*").b(); | |
/* | |
Output: | |
F.a * | |
F.this.a * | |
F.b.this.a * | |
F.a start|*|end | |
F.this.a start|*|end | |
F2.a * | |
F2.this.a * | |
F.b.this.a * | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment