如何理解es6中的class,以及class中的constructor函数

2025-05-16 04:24:10
推荐回答(1个)
回答1:

构造器 Constructor
我们先来看“构造函数方式”的具体做法:

function start(){
alert("Bang!!!");
}

//constructor
function Car(color, title){
this.color = color;
this.title = title;
this.start = start;
}

var car1 = new Car("red", "BMW");
var car2 = new Car("yellow", "VOIS");