做javascript继承的正确方法是什么

时间:2016-03-30 22:59:49

标签: javascript class inheritance prototype

Asuming:

function Animal(name) {
  this.name = name;
}
Animal.prototype.move = function() {
  // move
};
function Rabbit() {
  // do rabbit stuff
}

我看到人们以不同的方式继承遗产。请参阅下面的代码,但哪种方法正确?他们似乎都以同样的方式工作

Rabbit.prototype = Rabbit.prototype;
// or
Rabbit.prototype = Rabbit.prototype.__proto__;
// or
Rabbit.prototype = new Rabbit();

0 个答案:

没有答案