您的位置:首页 > 运维架构

oop实现方法与属性继承

2015-12-20 15:54 375 查看
<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;
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: