js继承问题

有关js继承的问题;

function Parent(){
        this.name = 'huachenyu'
      }
      function Child() {
        this.age = 12
      }

      Child.prototype = new Parent();      //Child继承Parent


      var test = new Child();
      alert(test.age)   //12

  alert(test.name)  //huachenyu

 

  function bro(){
        this.sex = 'boy'
      }

      bro.prototype = new Child();  //同理,bro继承Child
      var test1 = new bro();
      alert(test1.sex)  //boy

posted @ 2019-03-21 18:42  落落1  阅读(111)  评论(0编辑  收藏  举报