469,916 Members | 1,985 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

Can I write this shorter?

Hello

I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));

Thanks
// Smyken
Jul 20 '05 #1
3 1184
You can pass the parameter inside an string with a string separator like ";"
and split into an array inside the function. Then make a For Loop and make
the operation for each element in the array...this allows you to pass any
number of elements to the function.

Raul Carrillo

"Smyke" <me*****@ing.umu.se> escribió en el mensaje
news:6c**************************@posting.google.c om...
Hello

I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));

Thanks
// Smyken

Jul 20 '05 #2
me*****@ing.umu.se (Smyke) writes:
I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));


Not unless the function changeout is build to understand it. There is
a big difference between calling a function once and calling it three
times.

Unless you have *many* calls, I doubt you save anything by making an
easier way to call the function. The extra code required for that will
take more work than just calling three times.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3
"Smyke" <me*****@ing.umu.se> wrote in message
news:6c**************************@posting.google.c om...
I have this code:
changeout('sub1'); changeout('sub2'); changeout('sub3');

and wonder if its possible to shorten it? To something like this:
changeout (('sub1'),('sub2'),('sub3'));


Perhaps:

for (var i=1;i<=3;i++){
changeout("sub"+i);
}

or

function chgout(){
for (var i=0;i<arguments.length;i++)
changeout(arguments[i]);
}

and then

chgout('sub1','sub2','sub3');

HTH,

Vjekoslav
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

16 posts views Thread by Krakatioison | last post: by
4 posts views Thread by Aki | last post: by
8 posts views Thread by Servé Lau | last post: by
18 posts views Thread by jacob navia | last post: by
11 posts views Thread by Michael Powe | last post: by
3 posts views Thread by skanemupp | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.