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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:31:44+00:00 2026-06-02T19:31:44+00:00

I have a constructor function, for example webapp.core.cf1 or Backbone.Router. But I get this

  • 0

I have a constructor function, for example webapp.core.cf1 or Backbone.Router. But I get this constructor function not as a reference, but as a string! I cannot change this requirement, the constr. must be in a string. How can I make a new object from this, for instance classfun(“Backbone.Router”)?

function classfun (cfstr) 
{ 
  ...
  cf = new window[cfstr]();

If I try it this way, I get the error: … is not a constructor.

Why this does not work? Is there an alternative way without using eval()?

Thanks a lot in advance

EDIT

Thank you all for your answers!

Thank you, Tronix117, this was the problem!!

Thank you, Benjamin Schulte, for the 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-02T19:31:45+00:00Added an answer on June 2, 2026 at 7:31 pm

    If you try in your console:

    var A=function(a){this.test=a};
    b = new window["A"](3);
    console.log(b.test); // return 3
    

    So that means, you are trying to access something which is not in the scope of window, it should rather be something like that: window.something[“A”], if you don’t know what is something then you should use the function of Benjamin, otherwise use this one, because it’s way faster.

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

Sidebar

Related Questions

I have two constructor : function clsUsagerEmailUserName($nickName, $email) { $this->nickName = $nickName; $this->email =
I have this code: dojo.declare(City, null, { constructor : function(cityid, cityinfo){ } }); dojo.declare(TPolyline,
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I have lots of code like this in my constructors:- function __construct($params) { $this->property
This is what I have: class Calendar extends CI_Controller { public $extension; function __construct()
As an example say I have a class foo that does not have a
I have such example. function Rabbit() { var jumps = yes; }; var rabbit
Let's say I have a constructor Alpha: //[#1] Alpha = function(a,b){ attrib1 = a;
I have been trying to write a constructor function that would make an object
Suppose I have a class with a constructor (or other function) that takes a

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.