Created
August 26, 2017 17:03
-
-
Save Zabaa/899504d3739d80b22ab744f14ee26272 to your computer and use it in GitHub Desktop.
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
namespace editors { | |
export function getEditorClasses(): FactoryConstructor[] { | |
let list = []; | |
Object.keys(this).forEach(name => { | |
let obj = this[name]; | |
if (obj.prototype instanceof editors.Factory) { | |
list.push(obj); | |
} | |
}); | |
return list; | |
} | |
export interface FactoryConstructor { | |
new(): Factory; | |
} | |
export abstract class Factory { | |
public abstract create(); | |
} | |
export class BugFactory extends Factory { | |
public create() { | |
console.log("Call BugFactory create"); | |
} | |
} | |
export class TaskFactory extends Factory { | |
public create() { | |
console.log("Call SomethingEditor create"); | |
} | |
} | |
} | |
var factories = editors.getEditorClasses(); | |
factories.forEach(function(fact){ | |
var f = new fact(); | |
f.create(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment