Next Generation Emulation banner

1 - 3 of 3 Posts

·
The Upcoming Rookie
Joined
·
620 Posts
Discussion Starter #1
I had this piece of code, which was unusually big, so I improved it; I have several different versions, and I need some help deciding which is appropriate.

Here is the original:

Code:
function preload(img1, img2, img3, img4, img5, img6, img7, img8, img9, img10, img11, img12, img13, img14, img15)
	{
	if(document.images)
		{
		var img = [new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image, new Image];
		img[0].src = img1;
		img[1].src = img2;
		img[2].src = img3;
		img[3].src = img4;
		img[4].src = img5;
		img[5].src = img6;
		img[6].src = img7;
		img[7].src = img8;
		img[8].src = img9;
		img[9].src = img10;
		img[10].src = img11;
		img[11].src = img12;
		img[12].src = img13;
		img[13].src = img14;
		img[14].src = img15;
		}
	else
		{
		img[0].src = "";
		img[1].src = "";
		img[2].src = "";
		img[3].src = "";
		img[4].src = "";
		img[5].src = "";
		img[6].src = "";
		img[7].src = "";
		img[8].src = "";
		img[9].src = "";
		img[10].src = "";
		img[11].src = "";
		img[12].src = "";
		img[13].src = "";
		img[14].src = "";
		document.images = "";
		}
	}
And here are the different versions.

Code:
function preload()
	{
	var img = new Array();
	for (number = 0; number < preload.arguments.length; number++)
		{
		if(document.images)
			{
			img[number] = new Image();
			img[number].src = preload.arguments[number];
			}
		else
			{
			img[number] = "";
			img[number].src = "";
			document.images = "";
			}
		}
	}
Is that good enough?

Or:

Code:
function preload()
	{
	var img = new Array();
	var number = 0;
	for (number in img)
		{
		number < preload.arguments.length; 
		number++;
		if(document.images)
			{
			img[number] = new Image();
			img[number].src = preload.arguments[number];
			}
		else
			{
			img[number] = "";
			img[number].src = "";
			document.images = "";
			}
		}
	}
Or:

Code:
function preload()
	{
	var img = new Array();
	var number = 0; 
	while (number < preload.arguments.length)
		{
		number++; 
		if(document.images)
			{
			img[number] = new Image();
			img[number].src = preload.arguments[number];
			}
		else
			{
			img[number] = "";
			img[number].src = "";
			document.images = "";
			}
		}
	}
 

·
Registered
Joined
·
1,208 Posts
Basically, there is no difference between the 3. It's just a different way to iterate over the list. I'd prefer the second (with for(blah in blub)), for no special reason.

There shouldn't be any performance problems with any of the 3 versions.
 

·
The Upcoming Rookie
Joined
·
620 Posts
Discussion Starter #3
Nezzar said:
Basically, there is no difference between the 3. It's just a different way to iterate over the list. I'd prefer the second (with for(blah in blub)), for no special reason.

There shouldn't be any performance problems with any of the 3 versions.
Thanks.
 
1 - 3 of 3 Posts
Top