【发布时间】:2015-03-12 21:43:57
【问题描述】:
function Car(model, color, power){
this.model = model;
this.color = color;
this.power = power;
this.is_working = true;
this.sound = function(){
console.log("Vrummm!");
};
}
function Car_optionals(){
this.turbo_boost = true;
this.extra_horsepower = 20;
this.name_tag = "Badass";
}
Car.prototype = new Car_optionals();
var Audi = {};
Audi.prototype = new Car();
console.log(Audi.is_working);
所以我也有这个类 Car 和 Car_optionals,我希望新创建的对象 Audi 继承 Car 和 Car_optionals 类的属性。可以在对象字面量中继承属性和方法吗?
【问题讨论】:
标签: javascript oop inheritance javascript-objects prototype-chain