title: Vanilla Javascript how override added function on event listener?
body: <p>I have a bootstrap modal that has some custom events, like hidden.bs.modal, depending on where the user does, I want the function in this event to be replaced, maybe it's better to understand with a simple example, consider:</p>
  <pre class="lang-js prettyprint-override"><code>const currentModal; // imagine an any modal here.
  
  window.addEventListener('load', () =&gt; {
     currentModal.addEventListener('hidden.bs.modal', standardFunction );
  });
  
  function standardFunction(){
      alert('hi there');
     // this is standard output to modal closed
  }
  
  function buttonClickedChange(){
      // Here, i need override standardFunction
  
       this.standardFunction = function(){
           alert('modal event hidden.bs.modal changed with success!');
           // this must be override previous output
       };
  }
  </code></pre>
  <p>What happens is that regardless of the redeclaration of the function, the output for the method is still standard, this is because the eventlistener does not refer to the stored function but only &quot;copy&quot; its content and creates its scope only inside.</p>