if(typeof(GUEST_IDS) != undefined){
GUEST_IDS = GUEST_IDS.substr(1);
GUEST_IDS = GUEST_IDS.split(",");
for(GP in GUEST_POINTS){
GUEST_ON = 0;
for(GID in GUEST_IDS){
if(GUEST_IDS[GID] == GP){
GUEST_ON = 1;
}
}
if(GUEST_ON == 0){
GUEST_POINTS[GP].setVisible(false);
}
}
}else{
for(GP in GUEST_POINTS){
GUEST_POINTS[GP].setVisible(false);
}
}
当我提醒GUEST_IDS时它表示未定义,所以如果GUEST_IDS =未定义为什么代码运行就像if(typeof(GUEST_IDS)!= undefined){是真的?
答案 0 :(得分:2)
typeof
返回指定类型的字符串。另外,typeof
不需要parens,最好使用!==
而不是!=
:
if(typeof GUEST_IDS !== "undefined") {
其他要点:
var
for
循环迭代数组;不是for in
循环GUEST_IDS
正在从字符串更改为数组===
而不是==
var ids = GUEST_IDS.substr(1).split(",");