soundcloud/waveformjs — pull request #4 by ccoenen (2012-11-08 10:37:45+00:00)
Title: fixing #2 scope/closure problem

The wrong jsonp-function was removed (always the last one), if you did multiple calls to waveform.js in short succession. also fixes polluted window scope with jsonpN properties.

To confirm the bug:
- make 3 or more calls to your api in very quick succession (4 calls in a for-loop is where it broke for us).
- the last call WILL fail with a "null is not a function" or similar error.
- you will also still have window.jsonp1 and window.jsonp2 as a reference to their functions. only window.jsonp3 (or whatever the last one is) will get nullified.

The problem is, that the variable jsonp is not a local variable but a closure. It will therefore be used as a reference for ALL jsonp-Callbacks. Thus it has the same (i.e. last) value for all callbacks. We solve this, by referencing a local variable that is individual to every jsonp-callback.