<br><br><br><br><script> <BR>Object.prototype.addChild=function(oName, obj) <BR>{ <BR> eval("var p=this."+oName+"= new Object()"); <BR> this[oName]=obj; <BR> this[oName].parent=this; <BR>} <BR></script><br>效果演示:<br><div class="htmlarea"> <textarea id="runcode57506"> <script language="javascript" 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> </textarea><br><input onclick="runEx('runcode57506')" type="button" value="运行代码"> <input onclick="doCopy('runcode57506')" type="button" value="复制代码"> <input onclick="doSave(runcode57506)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div>