By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,716 Members | 1,304 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,716 IT Pros & Developers. It's quick & easy.

Can I write this shorter?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
"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.