JS scope of member functions
"From this, I see that JS joins the scope of a function with a function (recursively) called in itself."

No, it doesn't.  You created a global variable called "r", not a method variable, and so there is only one "r", and it is accessible to all your JavaScript code.

Thou shalt always use var to declare a variable.