}else{ //eval(" var player_"+array.childNodes(0).text); // newobj=eval( "player_"+array.childNodes(0).text);
this["player_"+array.childNodes(0).text] = new game(document.documentElement,document.getElementById('game')); // eval( ) = new game(document.documentElement,document.getElementById('game'));
举个例子for (var i = 0; i < 10; i++) {
this["a" + i] = new go(1,i);
}
这个是全局的 因为window是全局对象,而for不是个基础模块,即this = window
其次,永久是不可能的,当然在当前的WEB文件里是存在的。不会离开for就没了。
如果你是在函数内去声明的话 不能用this了。你需要用window或者其他全局变量名
我就是说呢.但是我用你的方法.在内部申明的.外部也能访问到.好奇怪.
我觉得应该是
this.obj和 this[].obj的区别吧.
用window也可以.我试了.但是this[].obj函数之外也能访问.好奇怪.
如果你把你的代码贴出来 我可以给你解释下
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
//alert(xmlHttp.responseText);
//document.getElementById('xy-1').value=xmlHttp.responseText;
// alert(xmlHttp.responseText);
var obj=xmlHttp.responseXML.documentElement;
// var root=xmldom.documentElement;
/* for(i=0;i<root.childNodes.length;i++)
{
if(root.childNodes(i).childNodes(2).text!="")
{
imgstr="<img src=\"biaoqin/"+root.childNodes(i).childNodes(2).text+".gif\" />";
}
}*/
playeridvalue=document.getElementById('playerid').value;
var playerid= new Array();
playerid=playeridvalue.split(",");
i=0;
while(array=obj.childNodes(0).childNodes(i)){
j=1;
while(playerid[j]){;
if(playerid[j]==array.childNodes(0).text){
pobj = eval( "player_"+playerid[j]);
//alert(array.childNodes(1).text);
//错701700699
pobj.ajaxmove(array.childNodes(1).text,array.childNodes(2).text);
}else{
//eval(" var player_"+array.childNodes(0).text);
// newobj=eval( "player_"+array.childNodes(0).text);
this["player_"+array.childNodes(0).text] = new game(document.documentElement,document.getElementById('game'));
// eval( ) = new game(document.documentElement,document.getElementById('game'));
eval( "player_"+array.childNodes(0).text).addgirl("../images/gamepeople/girl.gif",60,65,array.childNodes(1).text,array.childNodes(2).text,20,playerid[j]);
}
j++;
}
i++;
}
}
}
}function aa(){
alert(eval("player_"+3));
}
setInterval("aa()",3000);
是一个函数调用的.myRequest这个是AJAX反返回XML执行的函数.
那么这个this=>window
喔.反正都行.不过我还是用window[play_"+i+"] = new go(1,i);
这个把.呵呵.
1、在javascript中。最基本的模块是函数,
2、在一个html文件中window是全局变量。即当前的所有全局变量其实都包含在window里。比如<script type="text/javascript">
name = "cj205";
if(1==1) {
sex = "male";
}
</script>那么其实name是window.name。而这个sex其实也是window.sex。