Object.create() 是什么?继承(继承特定的)

来源:互联网 发布:linux退出命令行界面 编辑:程序博客网 时间:2024/06/05 19:08
function Car (desc) {
    this.desc = desc;
    this.color = "red";
}
 
Car.prototype = {
    getInfo: function() {
      return 'A ' + this.color + ' ' + this.desc + '.';
    }
};
//instantiate object using the constructor functionvar car =  Object.create(Car.prototype);
car.color = "blue";
alert(car.getInfo());

0 0