以前,当我需要存储大量相关变量时,我会创建一个类。
function Item(id, speaker, country) {
this.id = id;
this.speaker = spkr;
this.country = country;
}
var myItems = [
new Item(1, 'john', 'au'),
new Item(2, 'mary', 'us')
];
但我想知道这是不是一个好的做法。有没有其他更好的方法在Javascript中模拟结构?
https://stackoverflow.com/questions/502366
复制相似问题