Skip to content

Instantly share code, notes, and snippets.

@andevsoftware
Last active March 11, 2016 07:55
Show Gist options
  • Save andevsoftware/5edd81f6037be063b562 to your computer and use it in GitHub Desktop.
Save andevsoftware/5edd81f6037be063b562 to your computer and use it in GitHub Desktop.
TypeScript Constructed example
class A {
public get static() {
return Object.getPrototypeOf(this).constructor;
}
constructor() {
console.log('constructor A');
this.constructed(A);
}
public constructed(type:any) {
if (type === this.static) {
this.initialize();
}
}
public initialize() {
console.log('initialize A');
}
}
class B extends A {
constructor() {
super();
console.log('constructor B');
this.constructed(B);
}
public initialize() {
console.log('initialize B');
}
}
console.info('instantiate A');
var a = new A();
console.info('instantiate B');
var b = new B();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment