码迷,mamicode.com
首页 > 其他好文 > 详细

寄生组合式继承

时间:2014-10-07 16:58:23      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   sp   div   c   

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

 

寄生组合式继承

标签:style   blog   color   io   os   ar   sp   div   c   

原文地址:http://www.cnblogs.com/kedoudejingshen/p/4009370.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!