1 function Car(model, year, miles) {
2 this.model =
model;
3 this.year =
year;
4 this.miles =
miles;
5 }
6
7 Car.prototype.toString =
function() {
8 return this.model + " has done " +
this.miles + " miles"
;
9 };
10
11 var civic =
new Car("Honda Civic", 2009, 20000
);
12 var mondeo =
new Car("Ford Mondeo", 2010, 5000
);
13
14 console.log(civic.toString());
15 console.log(mondeo.toString());
简单说,构造函数就是new一个
转载于:https://www.cnblogs.com/qzsonline/p/3540640.html