可能重複:
Crockford’s Prototypal inheritance - Issues with nested objectsJavascript繼承 - 從另一個原型調用函數
我在得到以下代碼從原型原型B到執行功能相關的問題,並想知道是否有任何簡單的解決方案:
var Ob = function() {
test = 'hi';
}
Ob.prototype.A = {
that : this,
root : this,
goB : function() {
var that = this;
console.log('hello');
that.B.wtf();
}
}
Ob.prototype.B = {
that : this,
root : this,
wtf : function() {
var that = this;
console.log(that);
}
}
test = new Ob;
test.A.goB();
'那= this'不引用你的'Ob'實例,只是你把在'Ob.prototype'屬性的對象! – Bergi
相關:[與嵌套對象繼承的問題](http://stackoverflow.com/questions/10131052/crockfords-prototypal-inheritance-issues-with-nested-objects) – Bergi