寄生组合式继承

    function suber (name) {
          this.name=name;
          this.frend=["xx","yy"];
        }
        suber.prototype.sayName = function() {
              alert(this.name);
        };
        function sub(name,age){
            suber.call(this,name);
            this.age=age;
        }
        function inheritPrototype (sub,suber) {
          var prototype=Object(suber.ptototype);
          prototype.constructor=sub;
          sub.prototype=prototype;
        }
        inheritPrototype(sub,suber);
        sub.prototype=new suber();
        sub.prototype.sayName = function() {
              alert(this.name+"xxxxxxxxx");
        };
        var su=new sub("sun zi",33);
        su.frend.push(33);
        // alert(su.frend.toString());
        var suber=new suber("lao zi");
        su.sayName();
        suber.sayName()
        // alert(suber.frend.toString()+"=  "+suber.sayName());
原文地址:https://www.cnblogs.com/kedoudejingshen/p/4009370.html