function a(){
alert(">>>"+(this==aa))//a,window,aa都返回false   这里的this是谁的啊??
this.b={
ss: function(){
alert(this==aa.b)//返回true
}
}
}
var aa=new a()
aa.b.ss()

解决方案 »

  1.   

    3楼,这个道理很简单因为在创建a()实例的时候aa变量还没值。function a(){
        alert(typeof aa)//<<<<<<<<undefined
        this.b={
            ss: function(){
                alert(this==aa.b)//返回true
            }
        }
    }
      

  2.   

    new a()运行完毕后aa才被赋值。
      

  3.   

    在楼主的代码上加了几行:
    this.x = 'x';
     function a(){
     this.x = 'a';
     alert(">>>"+this + this.x)
     this.b={
     ss: function(){
    46 x:'b',
    47 this.x = 'ss';
    48 alert(this + this.x)//这个this是谁啊? 小弟试过 既不是aa 也不是window 难道是匿名的?
    49 }
    50 }
    51 }
    52var aa=new a()
    53aa.b.ss()
      

  4.   

    不小心发出去了-_-!在楼主的代码上加了几行: 
    this.x = 'x'; 
    function a(){
        this.x = 'a'; 
        alert(">>>"+this + this.x)
        this.b={
            x:'b',
            ss: function(){
                this.x = 'ss'; 
                alert(this + this.x)//这个this应该是ss的
            }
        }
    }
    var aa=new a()
    aa.b.ss()关系是:
    window
      |——a
         |——b
            |——ss
      

  5.   

    function a(){
    _this=this
    _this.ss=function(){
    alert(this==aa)
    }
    eval.call(_this,"alert('>>>>'+(typeof aa))")//false  晕 这时候还没有值啊~
    }
    var aa=new a()
    aa.ss()
      

  6.   

    更正!是this应该是b
    刚才的代码写错了个地方
        this.x = 'x'; 
        function a(){
            this.x = 'a';
            alert(">>>"+this + this.x)
            this.b={
                x:'b', // 刚才这里写错了-_-!
                ss: function(){
                   //this.x = 'ss';
                   alert(this + this.x)//这个this是b
                 }
            }
        }
        var aa=new a()
        aa.b.ss()
        alert(aa.b.x);
      

  7.   

    var _this
    function a(){
    _this=this
    _this.ss=function(){
    alert(this==aa)
    }

    }
    var aa=new a()
    eval.call(_this,"alert('>>>>'+(_this==aa))")//true
    eval.call(_this,"alert('>>>>'+(this==window))")//true 
    eval.call(_this,function(){this==aa})//true
    aa.ss()
      

  8.   

    var _this
    function a(){
    _this=this
    _this.ss=function(){
    alert(this==aa)
    }

    }
    alert(_this==aa)//这说明了  aa在new之前就被复制  只是没有办法调用吧  因为是匿名的?
    var aa=new a()
      

  9.   

    12楼那 错了  
    应该是 先执行的new  然后再执行alert