Last active
March 11, 2016 07:55
-
-
Save andevsoftware/5edd81f6037be063b562 to your computer and use it in GitHub Desktop.
TypeScript Constructed example
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 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