Structs in Javascript -


First, when I needed to store several related variables, I could have made a square.

  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', 'we')];  

But I'm thinking that this is a good practice. Are there better ways to emulate a strat in Javascript?

The difference between object literals and created objects is the properties obtained only from the prototype.

  var o = {'a': 3, 'b': 4, 'doStuff': function () {alert (this.a. this.b); }}; O.doStuff (); // Display: 7  

You can create a structure factory.

  function makeStruct (names) {var names = names.split (''); Var count = names.length; Function Constructor () {for (var i = 0; i  

Comments