构造函数继承为什么a.prototype = new b()不好?

时间:2016-10-05 00:17:04

标签: javascript inheritance constructor

我刚刚开始学习继承,而我刚刚开始学习基础知识。现在我想创建一个cylon的“子”构造函数,它继承了所有Cylon的属性。但我这样做的方式似乎被称为坏方法。为什么会这样呢?

function Cylon(model){
  this.attack = function(){return "Destroy all humans!"};
}

function HumanSkin(model){
}
HumanSkin.prototype =  new Cylon();
HumanSkin.prototype.infiltrate = function(){return "Infiltrate the colonies"};

0 个答案:

没有答案