在这里工作是我的代码:的Object.create不是在功能
function Mammal(name){
this.name = name;
this.offspring = [];
}
Mammal.prototype.sayHello = function(){
return "My name is " + this.name + ", I'm a " + this.constructor.name;
}
function Cat(name, color){
Mammal.call(this, name);
this.color = color;
}
现在,当我打电话的Object.create从这个函数:
function extendWithObjectCreate(child, parent) {
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
}
的Object.create不返回一个对象链接到父级原型。
你可以在函数中使用Object.create吗?
你能解释你如何调用'extendWithObjectCreate'吗? –
如何将'child'和'parent'传递给'extendWithObjectCreate'? –
extendWithObjectCreate(Child,Mammal) – HelloWorld