var varname, foo = function(){ var p = arguments.length==0 ? varname : arguments[0] alert(p) } foo(1) varname = 'test' foo()