Closed Thread Icon

Topic awaiting preservation: super mega quick question - zooooom! did you see it? (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=8655" title="Pages that link to Topic awaiting preservation: super mega quick question - zooooom! did you see it? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: super mega quick question - zooooom! did you see it? <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-15-2003 19:07

ok this may be really dumb question but how do you get the contents of a Function bracket into an array?

basically I have this line in my document:

loadsrc('main.js','menu.js','sidemenu.js','artistlist.js');

and this script in a separate js file:

function loadsrc(src) {
js = new Array(src)

*** blah blah blah, more script here ***
}

why does the function only read the first entry 'main.js'? I need all to go into the array sequentially.

help.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-15-2003 20:24

because you need an input variable in your array for each thing you are passing it. In the example you have posted you are only getting 'main.js'


function loadsrc(src1, src2, scr3 ... etc


Easier to do (and more flexible) is to create an array of items you want included then pass that to your funciton

srcArray = new Array ('main.js','menu.js','sidemenu.js','artistlist.js');

then call load src like so
loadsrc(srcArray);


And loadsrc should look like

function loadsrc(srcs) {

}

Now srcs in the function loadsrc should be an array with all the files you want included



.:[ Never resist a perfect moment ]:.

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 05-16-2003 07:36

However, if you really like your method better, you can use the "arguments" array within the function to get at the arguments:

function loadsrc() {
js = new Array();
for (var a=0; a < arguments.length; a++)
js[a] = arguments[a];
}

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-16-2003 17:45

cool I couldn't remember if JS had that ability or not



.:[ Never resist a perfect moment ]:.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-16-2003 21:44

bitdamaged, your technique was good, but slime's is better. Thanks

« BackwardsOnwards »

Show Forum Drop Down Menu