偶尔看到js中有个这种用法,比如:
if(!("io" in window)){
setError("io not defined");
return false;
}
不是很明白,在网上又不知道用什么关键字来查询,所以在这里请教各位!

解决方案 »

  1.   

    判断数组中是否有成员,对象中是否存在属性,注意和hasOwnProperty()不同,原型中的属性也会被抓出来。
    var Person=function(name,age){
      this.name=name;
      this.age=age;
    };Person.prototype.hello=function(){
      alert('I\'m '+this.name+' ,'+this.age+' years old');
    };var p=new Person('Rattz',20);
    p.hello();alert('hello' in p);
    alert(p.hasOwnProperty('hello'));
      

  2.   

    判断在window对象中是否有io这个属性  查js 中in运算符的用法应该可以查到
      

  3.   

    我觉得也可以用一下写法代替
    if(io!=undefined)或者if(typeof(io)!='undefined')