I’m trying to find a way (if there is one) of shortening a type of code that I use a lot, when building arrays. Some functions end up with a _lot
Here’s what the code typically looks like:
function item(code,name,p11,p12,p13,p14,p21,p22,p23,p24,p31,p32,p33,p34,p41,p42,p43,p44,p51,p52,p53,p54) {
this.code = code;
this.name = name;
this.p11 = p11;
this.p12 = p12;
this.p13 = p13;
this.p14 = p14;
this.p21 = p21;
this.p22 = p22;
this.p23 = p23;
this.p24 = p24;
this.p31 = p31;
this.p32 = p32;
this.p33 = p33;
this.p34 = p34;
this.p41 = p41;
this.p42 = p42;
this.p43 = p43;
this.p44 = p44;
this.p51 = p51;
this.p52 = p52;
this.p53 = p53;
this.p54 = p54;
}
itemArray = new Array();
itemArray[0] = new item(‘ab680′,’Absolut Vodka’,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
This is a fairly standard type of code that I’ve seen everywhere. Thing is, in some functions I’d like to use 50 or more arguments, and it would make the code much cleaner if there was a way of looping this, or shortening it up some other way.. I haven’t seen a reference to this anywhere, so either it’s impossible, or noone has cared enough yet.
This isn’t pivotal to me in any way, I’d just like to know if there is a way to to it..
/JP