0
現在JS有class
,我想知道這3個「站」是否有區別。有相同的/相同的嗎? 在所有情況下,我可以station.label
類,對象和構造函數是否等價?
//1
export class Station {
public label: string;
public code: number;
constructor(label, code) {
this.code = code;
this.label = label;
}
}
let station = new Station("my label", "my code");
//2
function Station(label, code) {
this.label = label;
this.code = code;
}
let station = new Station("my label", "my code");
// 3
let station = { label: "my label", "code": my code }