I listen to $.route.delegate('someparam', ...) on the main of jsmvc, when it gets fired i decide which controller to load, and delete the old controller (if available), the problem i also use $.route.delegate('some-other-param') in the controllers, the problem is than when the controller is destroyed, it tries to $.router.undelegate('some-other-param') which causes an error:
**delegate is undefined:**
file: delegate.js
73: if(event.batchNum && delegate.batchNum === event.batchNum){
So as far i can see in the code, the problem is because i am calling undelegating inside a for loop that is query the delegates.
// for each delegate
for(var i =0; i < len; i++){
Is there a way to avoid this problem?
I couldn't find a way to do this, in the end i used bind for the 'someparam' (which is the outer listener) and delegate for 'some-other-param' which is the inner.
That is a workaround for the delete is undefined error.