これが現在の私のコードです(不要な要素は明らかに削除されています):
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();
これはの内容ですがmyfunc.js
、機能していません。
function() {
this.bar1 = "Hello World";
this.bar2 = function()
{
console.log("this is bar2");
};
}
これは機能しますが、ではなくbar
とbar2
を割り当てています。どうすればそれらを確実に割り当てることができますか?foo
foo[0]
foo[0]