試圖保持這個簡短。使用phpstorm查看我的代碼並得到一些錯誤。變量隱式聲明和原型
它說我的函數命名的位置有一個「變量隱式聲明」
function towngate10() {
updateDisplay(locations[10].description);
if (!gate10) {
score = score+5;
gate10 = true;
}
playerLocation = 10;
displayScore();
document.getElementById("goNorth").disabled=true;
document.getElementById("goSouth").disabled=false;
document.getElementById("goEast").disabled=true;
document.getElementById("goWest").disabled=true;
}
而且,我只是想確保我去我的原型正確 只是一個樣本
全球排列:
var locations = [10];
locations[0] = new Location(0,"Intersection","This is where you awoke.");
locations[1] = new Location(1,"Cornfield","The cornfields expand for miles.");
locations[2] = new Location(2,"Lake","A large lake that is formed by a river flowing from the East.", new Item(1,"Fish","An old rotting fish."));
locations[3] = new Location(3,"Outside Cave","Entrance to the dark cave.");
定位功能:
function Location(id, name, description, item) {
this.id = id;
this.name = name;
this.description = description;
this.item = item;
this.toString = function() {
return "Location: " + this.name + " - " + this.description;
}
}
如果這是普通的JS,'var locations = [10];'只會聲明一個包含一個元素('10')的數組,而不是一個包含10個插槽的「空」數組。 – Passerby
也許你應該使用'var'來聲明像'score'和'gate10'和'playerLocation'這樣的變量,以便它們不是隱式的全局變量。 – jfriend00
你認爲這與原型有什麼關係? – 2015-04-23 04:23:29