1

I came accross arguments.callee.caller which seemed to solve the problem unbinding anonymous functions, however I don't really understand why this works in some cases but not others.

//Example 1
document.addEventListener('click', function(event){
    console.log("Example 1");
    console.log(arguments.callee.caller);
    event.currentTarget.removeEventListener(event.type, arguments.callee.caller);
});

//Example 2
document.addEventListener('click', (function(event){
  return function(){
    console.log("Example 2");
    console.log(arguments.callee.caller);
    event.currentTarget.removeEventListener(event.type, arguments.callee.caller);
  }();
}));

Why does Example 2 successfully unbind, however Example 1 doesn't when all I am doing is returning an identical anonymous function?

Zze
  • 18,229
  • 13
  • 85
  • 118

0 Answers0