在這裏工作是我的代碼:的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