I have the following class for which I wish to create a series of instances:
function rashnik(size, name) {
var img = document.createElement('img');
img.src = "pics/"+name+".jpg";
img.height = size;
img.width = size;
img.id = name;
d = 300-size;
img.style.marginBottom = d/2;
img.style.marginLeft = 50;
var gal = document.getElementById("gallery");
gal.appendChild(img);
};
Now, Iv'e created this function to create the instances:
function creater(names) {// the argument "names" would be a two-dimensional array
for (var a = 0; a < names.length; a++){
var names[a][0] = new rashnik(names[a][1], names[a][0]); // right here is where I get the error
}
}
And this is how I try to call it:
var friends = [["adi","300"],["tom","200"],["sleg","100"],["dorc","50"],["dork","25"]];
creater(friends);
The thing is, the var names[a][0] part throws me an error, which I totally understand; I want to create an object whose name is the same as the string stored in names[a][0], but, well, it just doesn't work that way.
Does anyone have an idea as to what I could to to make it happen?