javascript父子通信_Javascript教程-查字典教程网
javascript父子通信
javascript父子通信
发布时间:2016-12-30 来源:查字典编辑
摘要:varparent={//say:function(){//alert("parent_say");},alert:function(){/...

<scriptlanguage="javascript"defer="defer">

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();

</script>

<scriptlanguage="javascript">

Object.prototype.addChild=function(oName,obj)

{

eval("varp=this."+oName+"=newObject()");

this[oName]=obj;

this[oName].parent=this;

}

</script>

效果演示:

[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类