首页 > Web开发 > 详细

inheritCombinedParasitic.js

时间:2015-11-10 19:01:55      阅读:223      评论:0      收藏:0      [点我收藏+]
// 寄生组合式继承
// 其基本思路是通过借用构造函数来继承属性,通过原型链的混成形式来继承方法,就是为了不必为了子类型的原型去调用父类型的构造函数


function inheritPrototype(superPerson,person)
{
  var prototype=Object.create(person.prototype);
  prototype.construtor = superPerson;
  superPerson.prototype = prototype;
}
function Person(name)
{ 
  this.name = name;
  this.frieds =  ["Jack", "John", "Kim"];
}
Person.prototype.getName = function(){
  console.log(this.name);
};
function SuperPerson(name,sex){
  Person.call(this,name);
  this.sex = sex;
}
inheritPrototype(SuperPerson,Person);
SuperPerson.prototype.getSex = function(){
  console.log(this.sex);
};
var Tom=new SuperPerson("Tom","man");
Tom.getName();//Tom

 

inheritCombinedParasitic.js

原文:http://www.cnblogs.com/cynthia-wuqian/p/4953741.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!