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 8916457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:14:49+00:00 2026-06-15T05:14:49+00:00

Example code demonstrating the behavior in question: export class NodePool { private tail: Node;

  • 0

Example code demonstrating the behavior in question:

export class NodePool {
    private tail: Node;
    private nodeClass: Function;
    private cacheTail: Node;

    constructor(nodeClass: Function) {
        this.nodeClass = nodeClass;
    }

    get(): Node {
        if (this.tail) {
            var node = this.tail;
            this.tail = this.tail.previous;
            node.previous = null;
            return node;
        } else {
            return new this.nodeClass();
        }
    }
}

Line 17 of the example (return new……) causes the compiler to complain that:
Value of type ‘Function’ is not newable.

What is the proper way to store the constructor of any arbitrary class in a variable so that I can later instantiate it.

  • 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-15T05:14:55+00:00Added an answer on June 15, 2026 at 5:14 am

    You can use a type literal to specify an object that can be new’d. This has the advantage of added type safety, too:

    export class NodePool {
        private tail: Node;
        private cacheTail: Node;
    
        constructor(private nodeClass: { new(): Node; }) {
        }
    
        get(): Node {
            if (this.tail) {
                var node = this.tail;
                this.tail = this.tail.previous;
                node.previous = null;
                return node;
            } else {
                return new this.nodeClass();
            }
        }
    }
    

    class MyNode implements Node {
        next: MyNode;
        previous: MyNode;
    }
    
    class NotANode {
        count: number;  
    }
    
    var p1 = new NodePool(MyNode);   // OK
    var p2 = new NodePool(NotANode); // Not OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example code: #include <cstdlib> #include <iostream> using namespace std; class A { public: A(int
There's a code example demonstrating feComposite to be found here: http://www.w3.org/TR/SVG/filters.html#feCompositeElement But the example
[ Edit: I'm replacing the original, confusing question with a simplified example demonstrating the
Example code: <html> <head> <script src=jquery-1.3.2.min.js type=text/javascript></script> <script src=jquery-ui-1.7.1.custom.min.js type=text/javascript></script> </head> <body> <table border=1
Example code : int main() { std::vector<int> v1{1, 2, 3, 4, 5, 6, 7,
The example code below works as as a server process. But when I add
The example code of section 10.6, the expected result is: after several iterations, the
I have the following example code: $dataProvider = new CActiveDataProvider('firstTable', array('criteria' => array( 'select'
I took the example code from the Kendo UI demos at http://demos.kendoui.com/web/grid/remote-data.html , binding
Just some example code here, but I have lists of strings that I want

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.