2012-03-27 63 views

回答

0

实测值来做到这一点的最好的方法是通过“这个”如在嵌套类的构造函数的参数,这样的 -

a = new function() { 
    this.x=2; 
    B=function(sup) { 
     this.y=sup.x; 
    } 
    this.b=new B(this); 
} 

alert(a.b.y); // Displays 2 
1

这工作,但我不知道你的代码是在任何情况下正确

a = new function() { 
    var x=2; 
    B=function() { 
     this.y=x; 
    } 
    this.b=new B(); 
} 

alert(a.b.y); //alerts 2 
alert(a.x) //alert undefined becuase x is private 

存在的JavaScript没有super,如果你读here你可以看到你可以通过实现在JavaScript inehritance超级方法