我正在尝试在 JavaScript 中使用 Object.Create。我目前有以下代码:
var vehicle = {
getModel: function () {
console.log( "The model of this vehicle is.." + this.model );
}
};
var car = Object.create(vehicle, {
"id": {
value: 9,
},
"model": {
value: "Ford",
}
});
var van = Object.create(vehicle, {
"id": {
value: 10,
},
"model": {
value: "Big Van",
enumerable: true
},
"make": {
value: "Warrior",
},
"getMake": function () {
console.log( "The make of this vehicle is.." + this.make );
}
});
我试图为 getMake 向 van 添加一个函数,但出现错误:
TypeError:当我调用时,对象# 的属性“getMake”不是函数:
van.getMake();
这可能吗?你怎么做呢?