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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:00:56+00:00 2026-06-17T17:00:56+00:00

Lets say I have a javascript class that looks like this: var Person =

  • 0

Lets say I have a javascript class that looks like this:

var Person = {
    //Private members

    getXmlRequestObj : function() {
            if (window.XMLHttpRequest) {
                return new XMLHttpRequest();
            } else if(window.ActiveXObject) {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } else {
                return "Your Browser needs an upgrade";
            }
        },

initialize: function() {
        Person.importHTML = Person.getXmlRequestObj();
    },


    //Set up the global content retrieval object
    //called importHTML
    //importHTML:  new ActiveXObject("Microsoft.XMLHTTP"),

    _status:'',

    getAjaxList:function(sWhat,sUrl) {
        if (Person.importHTML.readyState == 4 || Person.importHTML.readyState == 0) {
            Person.importHTML.open("GET", sUrl, false);// make it wait for the response
            Person._sWhat = sWhat;
            Person.importHTML.onreadystatechange = Person.handleListArrived; 
            Person.importHTML.send(null);
        }       
    },
     handleListArrived: function() {
        if (Person.importHTML.readyState == 4) {
            if(Person._sWhat=="units")
                Person._unitList = Person.importHTML.responseText;
            if(Person._sWhat=="ranks")
                Person._rankList = Person.importHTML.responseText;
        }
    }
}

instead of using this code:

            if(Person._sWhat=="units")
                Person._unitList = Person.importHTML.responseText;
            if(Person._sWhat=="ranks")
                Person._rankList = Person.importHTML.responseText;

I want it to use whatever Person._sWhat is to be the new member of Person. in other words
How do I make that assignment of a new member of Person dynamically? thereby making the code look something like this:

Person.something to the effect of Person._sWhat = Person.importHTML.responseText;

  • 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-17T17:00:56+00:00Added an answer on June 17, 2026 at 5:00 pm

    The dot notation is a convenience in JavaScript that is equivalent to square bracket notation:

    Foo.xyz === Foo['xyz']
    

    So, in your case

    Person[Person._sWhat+"List"] = Person.importHTML.responseText
    

    would be sufficient, but for the trailing "s" in your _sWhat field. If you can remove that elsewhere, that would be ideal. Alternatively:

    Person[Person._sWhat.slice(0,-1)+"List"] = Person.importHTML.responseText
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a JSON document / JavaScript object that looks like this:
Let's say you have a JavaScript class like this var DepartmentFactory = function(data) {
Let's say I have some simple Javascript like: <script> var hello = function(){ alert(Hello
Let's say that you have a Model that looks kind of like this: public
Let's say I have this javascript: <script language=javascript type=text/javascript> function addtext() { var newtext
let's say I have this code in javascript: function doAnAjaxCall () { var xhr1
Let's say I have this javascript function: function pauseComp(ms) { var date = new
Lets say I have a Javascript object: var myObj = { property1 : 20,
Lets say I have the following array in JavaScript: var skins = new Array('Light',
let's say I have a simple javascript like so: $(document).ready(function(){ if(login == 1) {

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.