我學習JavaScript和我有一些問題的功能召回...JavaScript方法調用和打印
這些是我的兩個功能: 第一:
function geisson() {
var iabile = new XMLHttpRequest();
iabile.onreadystatechange = function() {
if (iabile.readyState == 4) {
var objectjson = {};
var arrayCards = []; //creazione dell'array che conterrà le cards
objectson = JSON.parse(iabile.responseText);
arrayCards = objectson.cards;
var Ettore = []; //Vèttore di cards
//the results
for (i = 0; i < arrayCards.length; i++)
document.getElementById('image').src = "http://www.mysite.com/png/public/card/" + arrayCards[i].__guid__ + "?width=292";
}
}
iabile.open("GET", "gnekcard.json", true);
iabile.send(null);
}
和第二功能:
function Entity() {
var iabile = new XMLHttpRequest();
iabile.onreadystatechange = function() {
if (iabile.readyState == 4) {
var objectjson = {};
var arrayCards = []; //creazione dell'array che conterrà le cards
objectson = JSON.parse(iabile.responseText);
arrayCards = objectson.cards;
//the results
for (i = 0; i < arrayCards.length; i++)
document.getElementById('informazioni').innerHTML += "\r\n" + "Nome : " + arrayCards[i].__title__ + "\r\n" + "Vanity url: " + arrayCards[i].vanity_urls[0] + "\r\n";
}
}
iabile.open("GET", "gnek.json", true);
iabile.send(null);
}
我想有第三功能,打印的其他2個函數的結果。我寧願只在第三個函數中擁有「for」,並回想其他方法的向量,但它們不是全局的。我不想有全局變量(如果可能的話),那我該怎麼做呢?