[英]Object not defined but i think scope and declaration is ok
When I try to run a method from this object it says that the object is not defined.当我尝试从此对象运行方法时,它说该对象未定义。 I'm sorry if it's a stupid question I checked many times and cant seem to find an error so I appreciate your help and patience.
如果这是一个愚蠢的问题,我很抱歉,我检查了很多次并且似乎找不到错误,所以我感谢你的帮助和耐心。
let Sunce= {
dvaujedan: function (name){
this.prva(name);
this.druga();
},
prva: (name){
switch(name){
case "Elena":
player = new Player ("Elena" , 100, 200, 50, 100, 400);
break;
case "Anabel":
player = new Player ("Anabel" , 200, 300, 150, 200, 100);
break;
case "Silvia":
player = new Player ("Silvia" , 100, 200, 50, 200, 300);
break;
}
let getinterface =document.querySelector(".interface");
getinterface.innerHTML= '<img src="img/player/' +
player.name.toLowerCase() + '.jpg"> <h3>' +
player.name + '</h3><p>Speed:' + player.speed + '</p><p>Health:' +
player.health + '</p><p>Damage:' + player.damage +
'</p><p>Agility:' + player.agility +
'</p><p>Mana:' + player.mana + '</p>';
},
druga: (){}
}
It seems like the object will cause SyntaxError
because of prva
and druga
.由于
prva
和druga
该对象似乎会导致SyntaxError
。 You should add function
for those 2 functions.您应该添加
function
对于那些2种功能。
dvaujedan: function (name){
...
},
prva: function (name){
...
},
druga: function (){}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.