There is a way to make local variables and still use your function:
There are some limitations (vars must be global, etc), but maybe someone will find it helpful. I certainly have
Rather than declare local variables using the var keyword, instead make them as objects of the function. Also make the qq function a property of the local function and then you can use it to show the contents of those localized variables.
while (str.indexOf('$') != -1)
str = str.replace(/\$[^\s\W]+/,eval(str.match(/\$([^\s\W]+)/,"$1")));
var a = "A"
var b = "B"
document.write(qq('$a but not $b'))
this.c = "C"
this.d = "D"
this.qq = qq;
document.write(qq('$c but not $d'))