Previously, when I needed to store a number of related variables, I’d create a class.
function Item(id, speaker, country) { this.id = id; this.speaker = speaker; this.country = country; } var myItems = [new Item(1, 'john', 'au'), new Item(2, 'mary', 'us')];
But I’m wondering if this is a good practice. Are there any other, better ways to simulate a struct in JavaScript?
The only difference between object literals and constructed objects are the properties inherited from the prototype.
You could make a struct factory.