If I understood everything correctly, the reason was that the for-loop
doesn’t create a separate context, thus the reference to r was made for
the whole renderResonator function. This obviously references the latest
r after the loop has finished. Switching this to $.each where each
iteration is a new anonymous function and thus a closure, r is referenced
correctly.
Please reopen if this does not fix the problem.