T
Thomas Mlynarczyk
Hi,
I want to pass a variable to a function and that function should display
both the value and the name of that variable. As for the value - no problem,
but the name? So far I've come up with
function foo() {
var myVar = 5;
var myOtherVar = 'bla';
showVars( {myVar: myVar, myOtherVar: myOtherVar} );
}
function showVars(oVars) {
for(var sName in oVars) {
// Display sName and oVars[sName]
}
}
But this {myVar: myVar} is a bit awkward as I have to write everything
twice. Is there a more elegant way?
Greetings,
Thomas
I want to pass a variable to a function and that function should display
both the value and the name of that variable. As for the value - no problem,
but the name? So far I've come up with
function foo() {
var myVar = 5;
var myOtherVar = 'bla';
showVars( {myVar: myVar, myOtherVar: myOtherVar} );
}
function showVars(oVars) {
for(var sName in oVars) {
// Display sName and oVars[sName]
}
}
But this {myVar: myVar} is a bit awkward as I have to write everything
twice. Is there a more elegant way?
Greetings,
Thomas