1
나는 bullet.fire() 메서드를 호출하고 있습니다. 이 방법에서 나는 this.i ++, 유일한 문제는 this.i 모든 반복, 어떤 생각을 업데이 트하지 않는 이유는 무엇입니까? 루프에서메서드 호출에서 변수를 업데이트 루프
function projectile(){
this.i = 20;
}
projectile.prototype.fire = function(){
this.i++;
//shows value of this.i in a div
document.getElementById("info").innerHTML = this.i;
}
if(typeof(bullet) == "undefined"){
var bullet = new projectile(1);
}
bullet.fire();
쇼 전체 루프 코드 –
내가 document.getElementById를 ("정보") '없이 (복사 코드를 실행하고 일했다 this.i' = innerHTML을 . –
업데이트가 잘 안되므로 한 번에 모든 내용이 업데이트되므로 루프에 'alert (bullet.i);'를 넣으면 제대로 작동합니다. –