title: How to store/stash JavaScript event and reuse it later?
body: <p>From <a href="https://developers.google.com/web/fundamentals/app-install-banners/#trigger-m68" rel="noreferrer">https://developers.google.com/web/fundamentals/app-install-banners/#trigger-m68</a></p>
  
  <pre><code>let deferredPrompt;
  
  window.addEventListener('beforeinstallprompt', (e) =&gt; {
    e.preventDefault();
    // Stash the event so it can be triggered later.
    deferredPrompt = e;
  });
  </code></pre>
  
  <p>This code is fine, but I want to trigger the stashed event later, in a different place. To perform that, I need to store an event not just in a variable, but somewhere else.</p>
  
  <h2>The question: how can an event be stored with its methods?</h2>
  
  <p>I tried Local Storage with serialization/deserialization of an object:</p>
  
  <pre><code>&gt; localStorage.setItem('stashed-event', JSON.stringify(e))
  &gt;
  &gt; JSON.parse(localStorage.getItem('stashed-event'))
  </code></pre>
  
  <p>But this approach doesn't work as expected, because it's storing only key-values and losing all event methods.</p>