<script language="javascript" defer="defer">
var parent =
{
//
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();
var c = parent.child;
c.alert();
</script>
<script language="javascript">
Object.prototype.addChild=function(oName, obj)
{
eval("var p=this."+oName+"= new Object()");
this[oName]=obj;
this[oName].parent=this;
}
</script>
成效演示:
[Ctrl+A 全选 注:如需引入外界Js需刷新本领进行]
" varparent= { // say:function() { // alert("parent_say"); }, alert:function() { // alert("parent"); this.say(); } }; // parent.addChild("chil...
本文由今晚最快开奖现场直播发布于前端科技,转载请注明出处:javascript父子通信
关键词: