In a simple game-app, I'm trying to pass the anonymous event-callback function some arguments. I could only do it using an anonymous function since it fits into the context (its scope identifies the arguments). The problem is that the game has an option to restart. After restarting, it adds to the same nodes new event Listeners, and here as you may guess the old event-listeners are still there, which results in an improper functionality and overloaded app. The solution I could think of is to "refresh" by removing the old eventListeners before adding the new ones. But I could not find any way considering the event-callback function is anonymous!
So, what could be an alternative solution?
var adder = function(colorBox, num){
colorBox.addEventListener('click', function(){
eventCall(this, num);
});
}
var eventCall = function(t, num){
var clickedBox = t.style.backgroundColor;
....