Is there a way to declare an actual parameter of a function as a global variable? I'm looking for a way to do a function that checks if a global variable exists and then declares it if it doesn't.
uh, yes declare : fuction(name,val) { eval('if (typeof '+name+' == undefined) { ' +name+' = ' + val + '; return(false); }'); return(true); }
Ok thanks, I got it working with this: setvariable: function(variable,data){ eval("if (typeof(" + variable + ") == 'undefined'){" + variable + "= data;}"); } I think you forgot the brackets for typeof and that val needs to stay as a string. Oh and also you spelt function wrong.
typeOf is a function and not a keyword in Javascript, therefore you have to use brackets. nvm. Apparently it is a keyword hah.
http://javascript.about.com/od/reference/g/rtypeof.htm Sorry, I guess you can use spaces then. I'd rather use brackets though.