js Call

  /*call1:   
        //将A对象的方法放在B对象上执行
        */
        function ParentC()
        {
            this.Parent = "NOT-NULL";
        }
        function ChildC()
        {
            ParentC.call(this);
        }

        var c = new ChildC();
        alert(c.Parent);
        //NOT-NULL
        /*call2:
        //call3:继承 
        */
        function C3()
        {
            this.add = function(a, b)
            {
                return a + b;
            }
        }
        function C4()
        {
            this.sub = function(a, b)
            {
                return a - b;
            }
        }


        function C5()
        {
            C3.call(this);
            C4.call(this);
        }

        var c5 = new C5();
        //c5.add(5,2);//7
        //c5.sub(5,2);//3


        /* //js的call方法实现多重继承
        */
        function A()
        {
            this.Name = "A";
            this.SayHi = function()
            {
                alert(this.Name);
            }
        }
        function B()
        {
            this.Name = "B";
            this.Role = "PM";
            this.show = function()
            {
                alert(this.Name + "-" + this.Role);
            }
        }
        var a = new A();
        var b = new B();
        a.SayHi.call(b);
        //alert("B");

转载于:https://www.cnblogs.com/nalanken/archive/2011/02/18/1957852.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值