Hi guys, Just a simple and pretty stupid question... Is there a way to get this to work? function dbug(e) { e = e.split(','); console.log(this); var ret = ''; for(var i=0;i<e.length;i++){ ret = ret + e[i] + ': ' + eval(e[i]) + ', '; } console.log(ret); } PHP: Just want to make it easier for me to console.log, so using this I would do function test() { var variable1 = 'too stupid'; var variable2 = 'to properly comprehend'; var variable3 = 'how scope works'; dbug('variable1,variable2,variable3'); } PHP: and dbug would log to the console variable1: too stupid, variable2: to properly comprehend, variable3: how scope works Anyone know? Thanks
I read your post thrice but I am so sorry I could not make out what you really wanted. But I will drop a line hoping that that is what you were looking for. the keyword var is used to denote local variables, i.e variable which will exist within the function itself. Eg function sayHi() { var greetings=Hi dear, how are you? Hopes alls fine! document.write(greetings); //the variable greetings has an assigned value only in the function sayHi() if there was no var keyword before that, you could call that varaiable even outside the function } Code (markup):
Please try to remove var in the test() function... that will make variable1,variable2,variable3 become global variables. Otherwise thoses variables is only inside test() scope function test() { variable1 = 'too stupid'; variable2 = 'to properly comprehend'; variable3 = 'how scope works'; dbug('variable1,variable2,variable3'); }
function dbug() { console.log(this); var args = arguments, i = 0, l = args.length; for( ; i < l; i++) console.log(args[i]); } function test() { var variable1 = 'too stupid' ,variable2 = 'to properly comprehend' ,variable3 = 'how scope works'; dbug(variable1,variable2,variable3); } PHP: