BZ易风

导航

 

function People(){

  this.name='zhangsan';

  this.age = 20;

  this.run = fcuntion(){

   alert(this.name+'在运动');

  }  

}

//原生链

People.prototype.sex = '男';

People.prototype.work = function(){

  alert(this.name+'在工作');

}

//1.对象冒充实现继承:只能继承构造函数里的 不能继承原生链

function Person(){

  People.call(this);//对象冒充实现继承 只能继承构造函数里的 不能继承原生链

}

var a = new Person();

a.run();//可以实现

a.work();//不可以实现

//2.原生链实现继承:可以继承构造函数里的内容,也可以继续原生链里的内容

function Human(){

}

Human.prototype=new People();

var b = new Human();

b.run();//可以实现

b.work();//可以实现


问题:无法传参

var c = new Human('lisi',20);

会提示undefind在运动

 

posted on 2018-12-20 15:59  BZ易风  阅读(249)  评论(0编辑  收藏  举报