In a discussion at Passing 'this' and argument to addEventListener function without using bind, caching functions was mentioned.
For example, considering the following Event Listeners:
window.addEventListener('event1', callback1, false);
window.addEventListener('event2', callback2, false);
window.addEventListener('event3', callback3, false);
window.addEventListener('event4', callback4, false);
window.addEventListener('event5', callback5, false);
Can their removal be cached (for example in an array)?
var unloaders = []; // Keeps track of unloader functions
unloaders.push(window.removeEventListener('event1', callback1, false));
unloaders.push(window.removeEventListener('event2', callback2, false));
unloaders.push(window.removeEventListener('event3', callback3, false));
unloaders.push(window.removeEventListener('event4', callback4, false));
unloaders.push(window.removeEventListener('event5', callback5, false));
Finally, if they can be cached, how can they be executed at the correct time?
for (let i = 0, len = unloaders.length; i < len; i++) {
//
}