varparent=
{
//
say:function()
{
//
alert("parent_say");
},
alert:function()
{
//
alert("parent");
this.say();
}
};
//
parent.addChild("child",
{
//
say:function()
{
//
alert("child_say");
},
alert:function()
{
//
alert("child");
this.parent.say();
}
}
);
//parent.child.alert();
//parent.alert();
varc=parent.child;
c.alert();
Object.prototype.addChild=function(oName,obj)
{
eval("varp=this."+oName+"=newObject()");
this[oName]=obj;
this[oName].parent=this;
}
效果演示:
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]