js新手,求助function a(){
    this.b=100;
    this.c={
        d:function(){
                alert(this.b);//这里会弹出undefined,怎么才能显示function a()中的100?
        }
    }
}
var i=new a()
i.c.d()

解决方案 »

  1.   

    function a(){
    var me = this;
        this.b=100;
        this.c={
            d:function(){
                    alert(me.b);//这里会弹出undefined,怎么才能显示function a()中的100?
            }
        }
    }
    var i=new a()
    i.c.d()
      

  2.   

    你的function里的this指代的是this.c这个对象 而不是a对象
    所以把this指代提出来 就可以了