试图保持这个简短。使用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