码迷,mamicode.com
首页 > 其他好文 > 详细

oop实现方法与属性继承

时间:2015-12-20 17:10:26      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

<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;
};

oop实现方法与属性继承

标签:

原文地址:http://www.cnblogs.com/tfbodys/p/5061066.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!