【发布时间】:2013-11-08 12:57:02
【问题描述】:
我从一本书中得到了这个继承的例子:
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;
【问题讨论】:
-
我已经尝试创建最完整的 JavaScript 原型,(多重)继承,覆盖,使用 Super 和
this值答案在这里:stackoverflow.com/a/16063711/1641941 希望它有所帮助,如果您有任何问题,请随时问他们,以便我改进。
标签: javascript inheritance prototype