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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:58:41+00:00 2026-06-12T15:58:41+00:00

Here is my code currently (with unnecessary elements removed obviously): var foo = new

  • 0

Here is my code currently (with unnecessary elements removed obviously):

var foo = new Array();
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
    if (xhr.readyState == 4 && xhr.status == 200)
    {
        foo[0] = eval("(" + xhr.responseText + ")");
        // After this point, I want to be able to reference 
        // foo[0].bar1
        // and 
        // foo[0].bar2()
    }
}
xhr.open("GET", "myfunc.js", true);
xhr.send();

This is the content of myfunc.js, but it’s not working.

function() {
    this.bar1 = "Hello World";
    this.bar2 = function()
    {
        console.log("this is bar2");
    };
}

This works, but it’s assigning bar and bar2 to foo rather than foo[0]. How can I ensure that it assigns them to foo[0]?

  • 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-12T15:58:42+00:00Added an answer on June 12, 2026 at 3:58 pm

    I’ve ended up using JSON (as Quentin suggested) instead of defining a self modifying function.
    My resulting myfunc.json file looks like:

    {
        "bar1": "Hello World",
        "bar2": function()
        {
            console.log("this is bar2");
        }
    }
    

    As for the structure, I’m not overly concerned about it. It’s running on LAN only and is meant to demonstrate an idea I had about WebGL rather than being a practical, fully finished game.

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

Sidebar

Related Questions

Here is the code I'm currently using: $.ajax({ success: function(){ $('.post_container').append('test <br />'); }
Here's the code I'm currently working with: http://jsfiddle.net/gEMCm/ I'm trying to make an image
I'm currently using the validation code listed here in an application. I'd like to
I currently have a complete cover background image. Here is the code: #back{ /*
Here is what I am currently using for the code and it's not working
Here's a piece of code, currently driving me nuts. It's a UIView, with an
A coworker of mine started with this code: var newList = new List<>(); foreach(var
Here is my code currently. I'm making a java program that seaches Active Directory
Haskell here we go! Okay so here is an example of the code currently
so as the title says..... here is the code I currently wrote thinking it

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.