我有一個對象「父」,它有一個setter/getter方法「a」,並且此對象也有一個對象數組「我們稱之爲」數組「,用Object Constructor來創建,我認爲用」數組「內的對象我想訪問方法a。從對象數組中的一個對象訪問父集/ get方法
我把一些代碼更好undestanding:
function parent()
{
this.a; //This is a setter/getter method
this.array=[]; // array of objects
this.array.push(new child());
}
function child()
{
this.aParentMehod;
}
b=new parent();
什麼,我想要的是b.array[0].aParentMethod
回報b.a
,
順便說一句,我使用的對象構造,因爲我不知道有多少孩子的我將有,但這是一個更好的方法來做同樣的事情,請告訴我。
預先感謝您
編輯:
我已經這樣做achived:
function parent()
{
this.a; //This is a setter/getter method
this.array=[]; // array of objects
this.array.push(new child(self));
}
function child(self)
{
this.parent=self;
this.aParentMehod=this.parent.a;
}
b=new parent();
但是,當我更改父a
歡迎使用屬性,孩子porpety這麼想的變化和aParentMehod
顯示的是正式的a
我試着回答這個問題,但並不是很清楚,尤其是,因爲給出的代碼顯然是僞代碼... –
是的它是僞代碼導致所有的代碼非常大,這個想法是,我有一個未確定數量的孩子,當我加載一個文件時將被創建,並且所有孩子都有在父母對象 –