PDA

View Full Version : passing object around



topcoder1
22 Aug 2007, 2:40 PM
var val='hi';
var val2='hi2';
show({'name': val,
'name2': val2});
function show(conf){

}

val and val2 has to be constants as opposed to variables as shown in the above example, is there a way to get around it?

evant
22 Aug 2007, 3:06 PM
Constants? Why wouldn't you just do



show({'name': 'hi',
'name2': 'hi2'});
function show(conf){

}

topcoder1
22 Aug 2007, 3:11 PM
Because I need to pass these as variables as opposed to literal strings that I hardcode. any solution?
I want


var v1='hi1';
var v2='hi2';
show({'name': v1,
'name2': v2});
function show(conf){

}

evant
22 Aug 2007, 3:15 PM
You aren't making any sense.

First you say
val and val2 has to be constants as opposed to variables and then you say
ecause I need to pass these as variables as opposed to literal strings

So which is it? :-/

topcoder1
22 Aug 2007, 3:36 PM
when I say "has to be" I didn't mean it's my requirement, I mean otherwise there's an error. Nevermind it turns out that error was due to other unrelated issues. So both way works.