/*ES5使用class 继承*///方法对象function Car(options){ this.title = options.title;}//开车Car.prototype.drive = function(){ return "vromm"};//实例化const car1 = new Car({title:"事实上"});//继承function Toyota(options){ this.color = options.color; Car.call(this,options);///重要 }Toyota.prototype = Object.create(Car.prototype);Toyota.prototype.constructor = Toyota;//Toyota 拥有 drive方法const toyota = new Toyota({color:'red',title:"focus"});toyota.drive();/*es6 class 继承 可以用于封装 */class Car { constructor({title}) {//结构 this.title= title; } drive(){ return "vroom"; }}const car = new Car({title:"bmw"})class Toyota extends Car{//extends Car 是继承 constructor(options) { super(options);//继承 this.color = options.color; }}const toyota = new Toyota({color:"red",title:"ficus"});