javascript父子通信
JavaScript通信 父子
2023-06-13 09:13:56 时间
<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>
效果演示:
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>
效果演示:
相关文章
- 【说站】Javascript如何用原型对象继承父类型
- javascript 数组求和_javascript数组的定义
- JavaScript 与 Java、PHP 的比较详解编程语言
- 常用的javascript函数详解编程语言
- JavaScript学习总结(二十)——Javascript非构造函数的继承详解编程语言
- AJAX入门之深入理解JavaScript中的函数
- javascript双击文本框编辑功能代码
- 对象特征检测法判断浏览器对javascript对象的支持
- javascript与webservice的通信实现代码
- Javascript异步加载详解(浏览器在javascript的加载方式)
- javascript判断中文字符长度的函数代码
- JavaScript垃圾回收机制分析
- Javascript学习笔记之数组的遍历和length属性
- Javascript堆排序算法详解
- javascript基于HTML5canvas制作画箭头组件