【发布时间】:2015-04-24 11:49:08
【问题描述】:
一个快速但很难用谷歌搜索的问题:
var child = Object.create(parent.prototype);
var child = Object(parent.prototype);
它们是相同的吗?
编辑:
这两个用于实现寄生组合继承模式的 inheritPrototype 函数示例提出了我的问题。
function inheritPrototype(childObject, parentObject) {
var copyOfParent = Object.create(parentObject.prototype);
copyOfParent.constructor = childObject;
childObject.prototype = copyOfParent;
}
http://javascriptissexy.com/oop-in-javascript-what-you-need-to-know/
function inheritPrototype(subType, superType){
var prototype = object(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
}
"Parasitic Combination Inheritance" in Professional JavaScript for Web Developers
【问题讨论】:
-
在 Chromium 中
object未定义。 -
object应该是Object。 -
已经回答了一点,谢谢!小“对象”是引号而不是拼写错误-我猜在这种情况下是引号拼写错误;)
标签: javascript oop object prototypal-inheritance