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]?
I’ve ended up using JSON (as Quentin suggested) instead of defining a self modifying function.
My resulting
myfunc.jsonfile looks like: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.