a:function(){
alert(typeof this.name); 
alert(this.name);     
alert(typeof this.sex); 
alert(this.sex); 
}

解决方案 »

  1.   

    如果你想要的是person中的name,你要这样才可以:
    var person = {"sex":"male","name":"Jerry",a:function(){alert(typeof this.name); alert(this.name);     alert(typeof this.sex); alert(this.sex); } };     person.a(); this总是指向正在调用函数的对象。
    对于函数:a:function(){alert(typeof this.name); alert(this.name);     
    在执行函数person.a(); 的时候, 它沿着函数体->函数参数->global寻找name, 决不会找到person的name,因为person的name只是person的属性,它不存在作用域的问题。
      

  2.   


    var person = {"sex":"male","name":"Jerry",a:function(){alert(name in window);} };     person.a(); 那为什么上面的代码会返回FALSE呢?
      

  3.   

    alert("name" in window);
    这样才对
      

  4.   

    因为这里in 是一个关系判断符,用来测试右边的对象包以左边为名字的属性,她要求左边是一个可以转换成string的东西,
    如果你alert(name in window); 
    它会在全局查找有没有name这个变量,然后alert(name.toString() in window);<javascript权威指南 >关系操作符这一节有讲。
      

  5.   

    你可以这样测试:
    <script>
    var name = 'name';
    alert(name in window); 
    </script>