I'm a firm believer that eval() is inherently evil. So I would like to point out an alternative to it for this interesting function:
Code:
function qq(str) {
while (str.indexOf('$') != -1) {
str = str.replace(/\$[^\s\W]+/, this[str.match(/\$([^\s\W]+)/, "$1")[1]]);
}
return str;
}
When this function is called from the global scope, then "this" will point to window - in which all global variables are contained. If you call qq from a function, then it will try to find properties of that function instead, as outlined above by Roy Sinclair.
Just thinking about it, but have you also considered doing a global replace with backreference to a matched subpattern?