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

  • Home
  • SEARCH
  • 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 8797149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:47:29+00:00 2026-06-13T23:47:29+00:00

How can I pass in a class name as a variable using javascript? Let’s

  • 0

How can I pass in a class name as a variable using javascript?

Let’s say I have the class Person.

I want to pass in the name of the class to a function so that that function can call that class.

so the function is

function openClass(name)

I want to pass in

openClass('person')

so that openClass can call the class person

for example

function openClass(name)
{
    return new name() // here I want this line to actually 
                      // call the class "Person" if that is 
                      // what is passed in as a name parameter,

}
  • 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-13T23:47:31+00:00Added an answer on June 13, 2026 at 11:47 pm

    Technically, there are no classes in JavaScript. Although many third party libraries do create a class system on top of JavaScript.

    The “class” is typically a constructor function. So if you have the name of the function, it’s a matter of digging it out of the global scope. Assuming the function is defined globally:

    var Constructor = window[name];
    return new Constructor();
    

    If your function is actually defined at say my.namespace.Person, then it’s a bit more complicated, but still the same general idea.

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

Sidebar

Related Questions

If I have a auto_ptr I can pass it for a reference?Like: auto_ptr<MyClass>Class(new MyClass);
How can I pass parameters to the OnSuccess function of the AjaxOptions class in
I wrote a class that lets me pass in a list of variable types,
When I pass a Actionscript Value Object that contains a Date variable using BlazeDS
I want to make a class that will have a single get template method
I know that you can use the upload_to parameter to pass a callable function
You can pass special strings into jQuery's Datepicker class setDate() method like +7 which
Can I pass an objectify entity (i.e class annotated by @Entity ) to a
What is the highest class in the hierarchy I can use to pass HttpSessionState
In JSF 2 you can pass around ids, Strings other things that can be

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.