/    Sign up×
Community /Pin to ProfileBookmark

passing variables to functions

Hi,

I’ve got a long list of arguments that I need to pass to a function and I have been manipulating this list by creating a variable containing a string of the list. Some of the arguments are variables, some are strings. The trouble is if I try and pass this variable to the function, perhaps unsurprisingly, it doesn’t work. Is there any way for me to get the function to read this list as a string rather than as a variable? eg.

[code]
var mouseover = “‘over’,’navbar1′,’portfoliobar5_r9_c1′, swap,”,’portfoliobar5_r7_c1′,’images/Portfoliobar/portfoliobar5_r7_c1_f2.gif’,’images/Portfoliobar/portfoliobar5_r7_c1_f2.gif'”

//pseudo code:
for loop{
mouseover += some more stuff;}

MM_nbgroup(mouseover);
[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@rootJun 27.2007 — The variable is a container, like a box or a bag that has items in it, the item in your case is a String, this one'over','navbar1','portfoliobar5_r9_c1', swap,'','portfoliobar5_r7_c1','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif'which can be passed as a string shown as a list of items that are comma seperated.

You could pass the list as individual items to the function eg:myFunction('over','navbar1','portfoliobar5_r9_c1', swap,'','portfoliobar5_r7_c1','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif')which would in the function be accessed by the arguments[] array... or you could pass the arguments as ain individual arraymyArray = new Array('over','navbar1','portfoliobar5_r9_c1', swap,'','portfoliobar5_r7_c1','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif','images/Portfoliobar/portfoliobar5_r7_c1_f2.gif');
myFunction(myArray);
its a question of how you want to play it. You dont have to pass any parameters to a function, you could make the variable global and the function can be written so no arguments are passed but it accesses the variable directly.
×

Success!

Help @blask spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...