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