Home >Web Front-end >JS Tutorial >javascript father-son communication_javascript skills

javascript father-son communication_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 19:12:591123browse


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





Object.prototype.addChild=function(oName, obj)
{
    eval("var p=this." oName "= new Object()");
    this[oName]=obj;
    this[oName].parent=this;
}

效果演示:


[Ctrl A 全选 注:
如需引入外部Js需刷新才能执行]
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn