Can I write this shorter?

S

Smyke

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
 
R

Raul Carrillo Garrido a.k.a metsuke

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
 
L

Lasse Reichstein Nielsen

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
 
V

Vjekoslav Begovic

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);
}

and then

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

HTH,

Vjekoslav
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top