oop实现方法与属性继承

<script>
/*父类 Person*/
function Person(name,age){
  this.name=name;
  this.age=age;
}
Person.prototype.showName=function(){
  this.name;
};
Person.prototype.showAge=function(){
  return this.age;
};

function Worker(name,age,job){
  Person.apply(this,arguments); /*继承属性*/

  this.job=job;
}

Worker.prototype=new Person();/*继承方法*/
Worker.prototype.constructor=Worker;

Worker.prototype.showJob=function(){
  return this.job;
};

//使用对象
var p1=new Person('aaa',10);
var w1=new Worker('bbb',18,'厨师');

</script>

上一篇:【BZOJ4825】【HNOI2017】单旋(Link-Cut Tree)


下一篇:用高德地图API 通过详细地址获得经纬度