以下是关于js中的oop的一些问题(代码如下)。javascript中的多继承
<html>
<script>
function A(){
a = 'a - private FROM A()';
this.a = 'a - public FROM A()';
this.get_a = function(){
return a;
}
}
function B(){
this.b = 'b - private FROM B()';
this.a = 'a - public FROM B() ';
}
C.prototype = new A();
C.prototype = new B();
C.prototype.constructor = C;
function C() {
A.call(this);
B.call(this);
}
var c = new C();
//I've read paper about oop in Javacscript but they never talk
//(the ones have read of course) about multiple inheritance, any
//links to such a paper?
alert(c.a);
alert(c.b);
alert(c.get_a());
//but
//Why the hell is variable a from A() now in the Global object?
//Look like C.prototype = new A(); is causing it.
alert(a);
</script>
</html>
我想我应该澄清一下我的问题:js中多继承的缺点是什么?为什么变量a在全球范围内? – plehoux 2010-09-22 15:10:34
然后把这个问题 - 使用编辑按钮 – 2010-09-22 15:14:46