Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8650413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T13:48:54+00:00 2026-06-12T13:48:54+00:00

Im wondering how I can get a reference to a types constructor to pass

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T13:48:57+00:00Added an answer on June 12, 2026 at 1:48 pm

    You can use the constructor type literal or an object type literal with a construct signature to describe the type of a constructor (see, generally, section 3.5 of the language spec). To use your example, the following should work:

    interface IGeometry {
        x: number;
        y: number;
    }
    
    class GeometryTypeInfo
    {        
        constructor (public typeId: number, public typeName: string, public fnCtor: new (...args: any[]) => IGeometry) {
        }
        createInstance(...args: any[]) : IGeometry { return new this.fnCtor(args); }
    }
    
    class Point implements IGeometry {
        constructor(public x: number, public y: number) { }
    
        public static type_info = new GeometryTypeInfo(1, 'POINT', Point);
    }
    

    Notice the constructor type literal in GeometryTypeInfo‘s constructor parameter list, and the new call in the implementation of createInstance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just wondering how i can get the error causing LoginUser function to
I'm wondering how in MATLAB you can get a reference to a Java enum
I'm wondering how I can get my textbox to only accept digits and dots,
I was wondering how I can get the graphics card model/brand from code particularly
I am wondering how I can get the document title in LaTex, for use
I am wondering how I can get all the files with File Info and
I was just wondering how I can get a single tap to undo the
I am fairly new to Android programming and was wondering how I can get
I'm using VS 2010, and I'm wondering how I can get my c++ program
I know I can get answers here but I was wondering if anyone knows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.