【发布时间】:2012-01-31 13:52:51
【问题描述】:
是否可以从类中继承对象(引用)值?
function A()
{
this.x = {};
}
function B()
{
this.y = {};
}
B.prototype = new A();
//...
var b1 = new B();
var b2 = new B();
alert(b1.x == b2.x); // true
alert(b1.y == b2.y); // false
但我希望两者都是错误的...... B.x 对于每个 B 实例应该是不同的。
【问题讨论】:
-
但是只有一个A;如果你想要不同的 A,那么将单个 A 作为原型是行不通的。
标签: javascript object superclass inheritance