function create_plant(name,position_first,position_second)
{
this.name=name;
this.position_first=position_first;
this.position_second=position_second;
this.plant=function(a){
if((test==0)&&(this.name))
{
choose="";
test+=1;
var b=document.createElement("img");
var plant_name="img/plant_gif/"+this.name+".gif";
b.setAttribute("src", plant_name);
a.appendChild(b);
this.wait_for_time();
test=test-1;
}
}
this.wait_for_time=function(){
can_move=0;
var picture=this.name+"_gif";
document.getElementById(picture).style.display="none";
setTimeout("this.time_out()", 3*1000);
}
this.time_out=function(){
var old_picture=document.getElementById(this.name);
old_picture.src="img/plant/"+this.name+".png";
}
}
如上,我想在這個class中的wait_for_time函數中調用setTimeout,希望能夠在3秒鐘後調用這個class中的time_out方法,可是用this.time_out沒法令time_out執行,求能夠調用time_out的解決方法
setTimeout調用時第1個參數傳入一個匿名函數,在匿名函數中調用你要真正調用的類的方法。