title: Removing event listeners with anonymous function calls in JavaScript
body: <p>I'm trying to remove an event listener for created span elements where the function called is within a closure. I've tried various methods and none seem to work.</p>
  
  <pre><code>var MyClass = function () {}
  
  MyClass.prototype.addSpan = function (el) {
      var span = document.createElement('span');
      span.innerHTML = "Text here";
      el.appendChild(span);
      span.addEventListener('click', (function (obj) { 
          return function () { 
              obj.removeSpan(); 
          }
      })(this), false);
  }
  
  MyClass.prototype.removeSpan = function () {
      alert('removing span');
      this.removeEventListener('click', arguments.callee, false);
      // .... remove span .... 
  }
  
  myclass = new MyClass();
  
  myclass.addSpan(document.getElementById('box'));
  </code></pre>
  
  <p>I've also used </p>
  
  <pre><code>this.removeEventListener('click', (function (obj) { 
      return function () { 
          obj.removeSpan(); 
      }
  })(this), false);
  </code></pre>
  
  <p>in place of <code>this.removeEventListener('click', arguments.callee, false);</code> but had no luck.</p>
  
  <p>Any help is much appreciated!</p>