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在运动

 

相关文章:

  • 2021-04-17
  • 2021-09-15
  • 2022-12-23
  • 2022-12-23
  • 2021-05-01
  • 2021-06-02
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2022-01-03
相关资源
相似解决方案