我有一个对象“父”,它有一个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
我试着回答这个问题,但并不是很清楚,尤其是,因为给出的代码显然是伪代码... –
是的它是伪代码导致所有的代码非常大,这个想法是,我有一个未确定数量的孩子,当我加载一个文件时将被创建,并且所有孩子都有在父母对象 –