我有以下代碼:對於Var In Loop - 我可以省略一個變量嗎?
function Vanguard(name,grade,skill,power,shield,critical, type, nation, clan, race, imageURL){
this.name = name;
this.grade = grade;
this.skill = skill;
this.power = power;
this.shield = shield;
this.critical = critical;
this.type = type;
this.nation = nation;
this.clan = clan;
this.race = race;
this.imageURL = imageURL;
};
var database = {};
database['asura kaiser'] = new Vanguard("Asura Kaiser", 3, "Twin Drive!!", 11000, 0, 1, "Normal Unit", "Star Gate", "Nova Grappler", "Battleroid", "http://images4.wikia.nocookie.net/__cb20120428001646/cardfight/images/thumb/a/a6/VGE_BT01-008EN.jpg/300px-VGE_BT01-008EN.jpg");
database['king of knights, alfred'] = new Vanguard("King of Knights, Alfred", 3, "Twin Drive!!", 10000, 0, 1, "Normal Unit", "United Sanctuary", "Royal Paladin", "Human", "http://images2.wikia.nocookie.net/__cb20121009013434/cardfight/images/thumb/9/95/BT01-001EN_RRR.jpg/300px-BT01-001EN_RRR.jpg");
database['dragonic overlord'] = new Vanguard("Dragonic Overlord", 3, "Twin Drive!!", 11000, 0, 1, "Normal Unit", "Dragon Sanctuary", "Kagerou", "Dragon", "");
database['ceo amaterasu'] = new Vanguard("CEO Amaterasu", 3, "Twin Drive", 10000, 0, 1, "Normal Unit", "United Sanctuary", "Oracle Think Tank", "Human", "");
database['alfred - early'] = new Vanguard("Alfred - Early", 3, "Twin Drive!!", 10000, 0, 1, "Normal Unit", "United Sanctuary", "Royal Paladin", "Human", "");
function printVanguard(p, name){
for (var p in database[name]){
document.getElementById('output').innerHTML +=('<b>' + p.charAt(0).toUpperCase() + p.slice(1) + '</b>: ' + database[name][p] + '<br />');
}
};
在我printVanguard功能,是有辦法,我可以循環使用的變種,但打印出來之外的所有變量IMAGEURL?現在代碼可以工作,但我正在修改它,以便Vanguard對象中的imageURL變量不會被打印出來。
(這不是我完整的代碼,只有什麼是相關的。如果你需要我的完整的代碼讓我知道。)
''如果? –
太棒了!我曾嘗試過,但是在imageURL周圍省略了引號,這就是爲什麼它不能編譯。非常感謝!!! – Kamui
您已經使Vanguard成爲一門課程,因此您可以將打印功能移至該課程的某個功能。 – Philipp