从一本书中我得到了这个继承的例子:
var Animal = function(){};
Animal.prototype.sleep = function(){
// ...
};
var Cat = function(){};
// Cat is an animal
Cat.prototype = new Animal;
Cat.prototype.meow = function(){
// ...
};
var scratchy = new Cat();
scratchy.sleep();
scratchy.meow();
但这也有效,对我来说似乎更直观。你为什么不做呢?还是你?它是否创建引用而不是复制原型属性?
Cat.prototype = Animal.prototype;