Skip to content

Instantly share code, notes, and snippets.

@ronshapiro
Last active October 29, 2023 12:24
Show Gist options
  • Save ronshapiro/c8bb0a34517fbb90f6dddc8972677d65 to your computer and use it in GitHub Desktop.
Save ronshapiro/c8bb0a34517fbb90f6dddc8972677d65 to your computer and use it in GitHub Desktop.
Typescript rewriting constructor properties
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