Im wondering how I can get a reference to a types constructor to pass the function as a value. Basically, I would like to have a generic type registry that would allow instances to be created by calling a member function of a generic type registry instance.
For example:
class GeometryTypeInfo
{
constructor (public typeId: number, public typeName: string, public fnCtor: (...args: any[]) => IGeometry) {
}
createInstance(...args: any[]) : IGeometry { return this.fnCtor(args); }
}
}
Later:
class Point implements IGeometry {
constructor(public x: number, public y: number) { }
public static type_info = new GeometryTypeInfo(1, 'POINT', Point); // <- fails
// also fails:
// new GeometryTypeInfo(1, 'POINT', new Point);
// new GeometryTypeInfo(1, 'POINT', Point.prototype);
// new GeometryTypeInfo(1, 'POINT', Point.bind(this));
}
Anyone know if it is possible to reference a classes constructor function?