Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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')
- ];
- var o = {
- 'a': 3, 'b': 4,
- 'doStuff': function() {
- alert(this.a + this.b);
- }
- };
- o.doStuff(); // displays: 7
- 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
- {id: 1, speaker:"john", country: "au"}
Add Comment
Please, Sign In to add comment