Skip to content

Instantly share code, notes, and snippets.

@kespindler
Created November 15, 2011 00:20
Show Gist options
  • Save kespindler/1365673 to your computer and use it in GitHub Desktop.
Save kespindler/1365673 to your computer and use it in GitHub Desktop.
Javascript structs
function makeStruct(names) {
var names = names.split(' ');
var count = names.length;
function constructor() {
for (var i = 0; i < count; i++) {
this[names[i]] = arguments[i];
}
}
return constructor;
}
var Item = makeStruct("id speaker country");
var row = new Item(1, 'john', 'au');
alert(row.speaker); // displays: john
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment