//ES5的做法:
//function Car(options){
// this.style = options.style;
//}
//
//Car.prototype.owner = function(){
// return "ivan";
//}
//
//
//const car = new Car({style:"cool"});
//
//console.log(car.style);
//console.log(car.owner());
//
//function BMW(options){
// var self = this;
// Car.call(self,options);
// this.color = options.color;
//}
//
//BMW.prototype = Object.create(Car.prototype);
//BMW.prototype.constructor = BMW;
//
//const bmw = new BMW({color: "red", style: "bigger"});
//
//console.log(bmw);
//console.log(bmw.owner());
//ES6的做法
class Car{
constructor({style}){
this.style = style;
}
owner(){
return "ivan";
}
}
//const car = new Car({style : "cool"});
//console.log(car);
//console.log(car.owner());
class BMW extends Car{
constructor(options){
super(options);
this.color = options.color;
}
}
const bmw = new BMW({style:"bigger", color :"red"})
console.log(bmw);
console.log(bmw.owner());
//function Car(options){
// this.style = options.style;
//}
//
//Car.prototype.owner = function(){
// return "ivan";
//}
//
//
//const car = new Car({style:"cool"});
//
//console.log(car.style);
//console.log(car.owner());
//
//function BMW(options){
// var self = this;
// Car.call(self,options);
// this.color = options.color;
//}
//
//BMW.prototype = Object.create(Car.prototype);
//BMW.prototype.constructor = BMW;
//
//const bmw = new BMW({color: "red", style: "bigger"});
//
//console.log(bmw);
//console.log(bmw.owner());
//ES6的做法
class Car{
constructor({style}){
this.style = style;
}
owner(){
return "ivan";
}
}
//const car = new Car({style : "cool"});
//console.log(car);
//console.log(car.owner());
class BMW extends Car{
constructor(options){
super(options);
this.color = options.color;
}
}
const bmw = new BMW({style:"bigger", color :"red"})
console.log(bmw);
console.log(bmw.owner());