function test() {
this.a = {
b: 4
};
}
test.prototype.a = {
c: 5
};
var example = new test();
为什么example.a.c == undefined
?Javascript原型未定义而不是继承?
它不应该继承原型并返回5
?
如果这是不可能的,是有一些方法来添加代码返回原型?:
function test() {
this.a = {
b: 4,
c: *this.return.prototype*
};
}
你的原型将工作'example.a.c',除了'this.a'接管'test.prototype.a'优先。 – Barmar
@Barmar,所以它不像$ .extend()和2个创建新对象的对象a = {b:4,c:5};? – seahorsepip
这是正确的,原型不会递归合并。 – Barmar