Im αναρωτιούνται πώς μπορώ να πάρω μια αναφορά σε ένα κατασκευαστή τύπους για να περάσει τη λειτουργία ως αξία. Βασικά, θα ήθελα να έχουμε μια γενική μητρώου τύπου που θα επέτρεπε περιπτώσεις να δημιουργηθεί καλώντας μια συνάρτηση μέλος μιας γενικής παράδειγμα μητρώου τύπου.
Για παράδειγμα:
class GeometryTypeInfo
{
constructor (public typeId: number, public typeName: string, public fnCtor: (...args: any[]) => IGeometry) {
}
createInstance(...args: any[]) : IGeometry { return this.fnCtor(args); }
}
}
Αργότερα:
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));
}
Όποιος γνωρίζει αν είναι δυνατόν να αναφέρονται σε μια λειτουργία τάξεις κατασκευαστή;













